dimanche 28 juin 2015

Mon simple scanner en python

hello,

après une longue absence , je suis de retour pour partager un petit script dérivé d'un exercice python d'un de mes cours.

voila donc c'est un petit scanner de ports avec quelques options.(soyez indulgent je suis toujours débutant ^^)

voila le script:

Code:

#This script (-VESISC-)  is only for localhost ,and under conditions webscan
#WEBSCAN (scanning websites) only with autorisation of administrator/owner
#The usage of this tool is under your own responsability

#for some modules you fist need to install them
#EX: sudo pip install ipwhois (needs to be installed via terminal)

#This work is licensed under the Creative Commons Attribution-NonCommercial 4.0 International
#To view a copy of this license, visit http://ift.tt/1faivrI
#For more informations contact info@ch-info.org.

#(c) cc nc 4.0 info@ch-info.org

from socket import *
from ipwhois import IPWhois
import dns.resolver
import urllib2
from pprint import pprint
import sys


def scanner(ip,alpha, omega):
    print ""
    print ""
    print "Begin to scan..."
    print "--------------
    count_o = 0
    count_c = 0
    for ports in range(alpha, omega):
        try:
            print "Scanning port :%d" % (ports,)
            s = socket(AF_INET, SOCK_STREAM)
            s.settimeout(3)
            s.connect((ip, ports))
            s.settimeout(3)
            print "Port %d: is OPEN" % (ports,)
            count_o = count_o + 1           
            s.close()
        except:
            print "Port %d: is CLOSED" % (ports,)
            count_c = count_c + 1
            s.close()
    print "Scanning finished !"
    print "-----------------
    print ""
    print "Found %d OPEN ports" % (count_o,)
    print "And %d CLOSED ports" % (count_c,)

def whois(ip):
    print ""
    print "WHOIS: %s" % (address,)
    print "----- + "-" * len(address)
    who = IPWhois(ip)
    results = who.lookup(get_referral=True)
    pprint (results)

def banner(address):
    print ""
    print "BANNER:"
    print "-----
    address1 = "http://ift.tt/1NnBuQR
    header = urllib2.urlopen(address1).info()
    print(str(header))
   
def nslookup(address):
    rd4 = None
    print ""
    print "NSLOOKUP:"
    print "-------
    ns_l = dns.resolver.query(address, "MX")
    ns_2 = dns.resolver.query(address, "NS")
    ns_3 = dns.resolver.query(address, "A")
    ns_4 = dns.resolver.query(address, "SOA")   
    print "MX (mail exchange)"
    print "----------------
    for rdata in ns_l:     
        print (rdata)
    print "NS (name server)"
    print "--------------
    for rdata in ns_2:     
        print (rdata)
    print "A (address)"
    print "---------
    for rdata in ns_3:     
        print (rdata)
    print "SOA (start of authority)"
    print "----------------------
    print "The SOA record includes the following details:"
    print "The primary name server for the domain, which is xxx.xxxxxxx.com"
    print "or the first name server in the vanity name server list for vanity name servers."
    print "The responsible party for the domain, which is xxx.xxxxxxx.com."
    print "A timestamp that changes whenever you update your domain."
    print "The number of seconds before the zone should be refreshed."
    print "The number of seconds before a failed refresh should be retried."
    print "The upper limit in seconds before a zone is considered no longer authoritative."
    print "The negative result TTL (for example, how long a resolver should consider a"
    print "negative result for a subdomain to be valid before retrying)."
    print "------------------------------------------------------------------------------
    for rdata in ns_4:
        print (rdata)   
   
def choice():
    if address == "localhost":
        scanner(ip,alpha,omega)
    else:
        whois(ip)
        banner(address)       
        nslookup(address)
        scanner(ip,alpha,omega)
       
print "-------------------------
print "-VESISC- very simple scanner"
print "-------------------------
print ""
print "This script (-VESISC-)  is only for localhost ,and under conditions webscan"
print "WEBSCAN (scanning websites) only with autorisation of administrator/owner !!"
print "The usage of this tool is under your own responsability !"
print ""
print "This work is licensed under "
print "the Creative Commons Attribution-NonCommercial 4.0 International License."
print "To view a copy of this license, visit http://ift.tt/1eRQevT;
print "For more informations contact info@ch-info.org"
print ""
address = raw_input("Enter address (or localhost): ")
alpha = int(raw_input("Port (min):"))
omega = int(raw_input("Port (max):"))
try:
    ip = gethostbyname(address)
    host = gethostbyaddr(ip)
    print ""
    print "%s has the IP: %s" % (address, ip,)
    print "HOST :",host[0]
    print ""
    choice()
except:
    print "Address %s unreachable" % (address,)

et voici quelques resultats: (localhost)

Code:

---------------------------
-VESISC- very simple scanner
---------------------------

This script (-VESISC-)  is only for localhost ,and under conditions webscan
WEBSCAN (scanning websites) only with autorisation of administrator/owner !!
The usage of this tool is under your own responsability !

This work is licensed under
the Creative Commons Attribution-NonCommercial 4.0 International License.
To view a copy of this license, visit http://ift.tt/1faivrI.
For more informations contact info@ch-info.org

Enter address (or localhost): localhost
Port (min):70
Port (max):90

localhost has the IP: 127.0.0.1
HOST : localhost



Begin to scan...
----------------
Scanning port :70
Port 70: is CLOSED
Scanning port :71
Port 71: is CLOSED
Scanning port :72
Port 72: is CLOSED
Scanning port :73
Port 73: is CLOSED
Scanning port :74
Port 74: is CLOSED
Scanning port :75
Port 75: is CLOSED
Scanning port :76
Port 76: is CLOSED
Scanning port :77
Port 77: is CLOSED
Scanning port :78
Port 78: is CLOSED
Scanning port :79
Port 79: is CLOSED
Scanning port :80
Port 80: is OPEN
Scanning port :81
Port 81: is CLOSED
Scanning port :82
Port 82: is CLOSED
Scanning port :83
Port 83: is CLOSED
Scanning port :84
Port 84: is CLOSED
Scanning port :85
Port 85: is CLOSED
Scanning port :86
Port 86: is CLOSED
Scanning port :87
Port 87: is CLOSED
Scanning port :88
Port 88: is CLOSED
Scanning port :89
Port 89: is CLOSED
Scanning finished !
-------------------

Found 1 OPEN ports
and 19 CLOSED ports

2eme un petit test sur google:

Code:

---------------------------
-VESISC- very simple scanner
---------------------------

This script (-VESISC-)  is only for localhost ,and under conditions webscan
WEBSCAN (scanning websites) only with autorisation of administrator/owner !!
The usage of this tool is under your own responsability !

This work is licensed under
the Creative Commons Attribution-NonCommercial 4.0 International License.
To view a copy of this license, visit http://ift.tt/1faivrI.
For more informations contact info@ch-info.org

Enter address (or localhost): google.com
Port (min):79
Port (max):82

google.com has the IP: 216.58.208.206
HOST : par10s21-in-f14.1e100.net


WHOIS: google.com
-----------------
{'asn': '15169',
 'asn_cidr': '216.58.208.0/24',
 'asn_country_code': 'US',
 'asn_date': '2012-01-27',
 'asn_registry': 'arin',
 'nets': [{'abuse_emails': 'arin-contact@google.com',
          'address': '1600 Amphitheatre Parkway',
          'cidr': '216.58.192.0/19',
          'city': 'Mountain View',
          'country': 'US',
          'created': '2012-01-27T00:00:00',
          'description': 'Google Inc.',
          'handle': 'NET-216-58-192-0-1',
          'misc_emails': None,
          'name': 'GOOGLE',
          'postal_code': '94043',
          'range': '216.58.192.0 - 216.58.223.255',
          'state': 'CA',
          'tech_emails': 'arin-contact@google.com',
          'updated': '2012-01-27T00:00:00'}],
 'query': '216.58.208.206',
 'raw': None,
 'raw_referral': None,
 'referral': None}

BANNER:
-------
Date: Sun, 28 Jun 2015 10:19:55 GMT
Expires: -1
Cache-Control: private, max-age=0
Content-Type: text/html; charset=ISO-8859-1
P3P: CP="This is not a P3P policy! See http://ift.tt/xFQvOM for more info."
Server: gws
X-XSS-Protection: 1; mode=block
X-Frame-Options: SAMEORIGIN
Set-Cookie: PREF=ID=1111111111111111:FF=0:TM=1435486795:LM=1435486795:V=1:S=09AhYjBsABeBUXDB; expires=Tue, 27-Jun-2017 10:19:55 GMT; path=/; domain=.google.fr
Set-Cookie: NID=68=TCcBPXG60lnXOWv6uBWxeppYgk4BkPPNQRfGcLtrKObhLav7tSYvcDL60AbQP4-_5FxoM7OuHMQu9uQ6lOuVJPwOW00IHtsUDEBod4FfneFT19hu-XmMI78DSiiYPVnf; expires=Mon, 28-Dec-2015 10:19:55 GMT; path=/; domain=.google.fr; HttpOnly
Alternate-Protocol: 80:quic,p=0
Accept-Ranges: none
Vary: Accept-Encoding
Connection: close


NSLOOKUP:
---------
MX (mail exchange)
------------------
20 alt1.aspmx.l.google.com.
30 alt2.aspmx.l.google.com.
10 aspmx.l.google.com.
50 alt4.aspmx.l.google.com.
40 alt3.aspmx.l.google.com.
NS (name server)
----------------
ns2.google.com.
ns4.google.com.
ns1.google.com.
ns3.google.com.
A (address)
-----------
216.58.208.238
SOA (start of authority)
------------------------
The SOA record includes the following details:
The primary name server for the domain, which is xxx.xxxxxxx.com
or the first name server in the vanity name server list for vanity name servers.
The responsible party for the domain, which is xxx.xxxxxxx.com.
A timestamp that changes whenever you update your domain.
The number of seconds before the zone should be refreshed.
The number of seconds before a failed refresh should be retried.
The upper limit in seconds before a zone is considered no longer authoritative.
The negative result TTL (for example, how long a resolver should consider a
negative result for a subdomain to be valid before retrying).
--------------------------------------------------------------------------------
ns1.google.com. dns-admin.google.com. 4294967295 7200 1800 1209600 300


Begin to scan...
----------------
Scanning port :79
Port 79: is CLOSED
Scanning port :80
Port 80: is OPEN
Scanning port :81
Port 81: is CLOSED
Scanning finished !
-------------------

Found 1 OPEN ports
And 2 CLOSED ports


"ATTENTION: L'usage de cet outil est strictement réservé a un usage LEGAL
c'est a dire tout scan devra avoir l'autorisation du propriétaire/admin
du site web en question."


Toutes critiques constructives sont bien sur les bien venues ^^

ps: maintenant je devrais m'attaquer au multithreading (prochain exercice ^^),pour le scanner de ports (et la c'est une autre histoire ....)

ps2: Merci a fred pour m'avoir fait goutter python ^^

Passez une bonne journée :)

Salut.


from Hackademics : Forum de hacking – hackers white hat – cours de securite informatique, apprendre langage python, tutoriels de reverse engineering http://ift.tt/1eRQevV
via IFTTT

Aucun commentaire:

Enregistrer un commentaire