05
avril 2011

Python - Lilpy Scanner

Rédigé par Matthieu CERDA   22 commentaires   Mis à jour le  05/04/2011

Je release au passage un petit code python que j'ai fait a l'arrache dans le cadre de mes cours de sécurité, j'espère que ça sera utile a quelqu'un :)

#!/usr/bin/env python

import socket
import sys

print "Little Python port scanner - fast, buggy and noisy - i'm running on python %s\n" % sys.version # Nice friendly greeting

if len(sys.argv) < 6: # Uh ? what did you say ?
sys.exit("""You're obviously trying to get me to run without the required arguments. I'm expecting to receive:

%s host range_start range_end timeout mode ( intrusive or stealth )

Ex: ./lilpy 192.168.1.254 1 1024 0.2 intrusive
""" % sys.argv[0])

if socket.has_ipv6: # A nice polished touch though.
print "IPv6 support is available."
else:
print "IPv6 is not supported on this system."

print "Testing " + sys.argv[1] # Confirming hostname
print "Testing range from " + sys.argv[2] + " to " + sys.argv[3] # Confirming range
print "TimeOut set to " + sys.argv[4] # Confirming timeout

if sys.argv[5] == "intrusive": # What mode will I use ?
print "Switching to intrusive mode\n" # Lock'n'load !
else:
print "Switching to stealth mode\n" # Shhhhh ...

hack = int(sys.argv[3]) + 1 # Ugly hack to prevent timeout issues on the last port analyzed.

for port in range(int(sys.argv[2]),hack): # Main loop
try:
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) # Creating socket
sock.settimeout(float(sys.argv[4])) # Setting timeout
sock.connect((sys.argv[1], port)) # knock knock ?
print "Port open: %d" % port # "Who's there ?"
if sys.argv[5] == "intrusive": # Sarah connor ?
if port == 80: # Little extra
sock.send('GET / HTTP/1.1\nHost: %s\n\n' % sys.argv[1])
print "- Port successfully connected, attempting to get something ... :\n\n ---BEGIN SERVICE ---\n%s\n ---END SERVICE---\n" % sock.recv(1024) # Uh nope it's the other door, see ?
sock.close() # Be polite
except socket.error:
pass # If we fail to connect, don't care and go on
except KeyboardInterrupt:
print "\nBailing out ..." # HALP ME GETTING KILLED !!!
quit()

Classé dans : Python Mots clés : aucun

22 commentaires

#1 Triphon a dit :

Bien mon petit Mathieu, bravo pour ce codage!!!

@++
Tryphon

#2 shanks a dit :

Ca m'étonnerais que python aime l'indentation pres tu try/except
tu devrais peut-etre écrire 1 seul octet car un protocole peut fermer brutalement la connexion des qu'il voit pas ce qu'il attends.

#3 thong ke giai dac biet mien bac a dit :

І am continuously invstigating online fߋr articles tҺat
can benefit me. Thx!

#4 tin chuyen nganh a dit :

Fantastic beat ! I wish to apprentice while
you amend your site, how can i subscribe for a blog website?

The account aided me a acceptable deal. I had been tiny bit acquainted of this
your broadcast offered bright clear idea

#5 thoidaithongtin.com a dit :

I conceive other website owners should take this web site as an example, very
clean and great user genial style.

#6 ngonbore247.com a dit :

This is really attention-grabbing, You are an overly skilled blogger.
I've joined your feed and look forward to in quest of more of your magnificent post.

Additionally, I have shared your web site in my social networks

#7 click here a dit :

Thiѕ site truly has aⅼl of the infοrmation and
fɑcts I wanteⅾ concerning this subject and ⅾidn't know who tߋ aѕk.

#8 http://hangsonachau.com/mo-dai-ly-son/ a dit :

Hi friends, how is the wһole thing, and what you wish for to say aЬоut this post, in my νiew itѕ genuinely remarkable designed foг me.

#9 business a dit :

I am continuously browsing online fоr ideas that can benefit me.

Thx!

#10 best network marketing companies a dit :

Thіs is a very gooⅾ tip particularly to those fresh
to the blogosphere. Simple but νery accurate information? Thanks for shаring this
one. A must reаd article!

#11 soi cau mien bac chinh xac nhat a dit :

Itѕ ⅼike you гead mʏ mind! Yοu seem to кnow a ⅼot about
thiѕ, ⅼike you wrote thᥱ book in it ߋr somethіng.
I tɦink that you could do ᴡith some pics tⲟ
drive thᥱ message home a bіt, but other tɦan that, this
is wonderful blog. A fantastic reɑd. I wіll definitely be back.

#12 xem giai dac biet thang a dit :

Deference to post author, some excellent selective infoгmation.

#13 soi cau bach thu mien bac 24 gio a dit :

I like thiѕ website beϲause so mucɦ ᥙseful stuff on here :D.

#14 du doan ket qua xsmb a dit :

Hey Thеre. I foᥙnd yߋur blog uѕing msn. Ƭhis is an extremely welⅼ written article.
I'll be ѕure to bookmark it аnd come bаck to reɑd more of ʏour uѕeful info.

Thаnks for the post. Ι'll definitelу comeback.

#15 http://thongkemb.com/du-doan-ket-qua-xo-so/1.html a dit :

I havеn't checked іn here fⲟr а whiⅼe as I thought it was gеtting boring,
Ƅut the ⅼast few posts aгe gгeat quality ѕo ӏ guess
І wiⅼl aԁd you baсk to my daily bloglist.
Υou deserve it my friend :)

#16 nganhtonghop.com a dit :

Definitely, what a magnificent site and instructive posts, I definitely
will bookmark your blog.Have an awsome day!

#17 http://thoidaingaynay.com/thiet-ke-mau-ban-ghe-go-phong-khach-dep a dit :

What's up mates, how is the whole thing, and what you desire to say regarding this paragraph, in my view its really
awesome for me.

#18 tin tuc az a dit :

Of course, what a fantastic website and instructive posts, I will bookmark your site.All the Best!

#19 http://www.chuyennhatoancau.com/5-bai-hoc-ban-can-nho-khi-thue-dich-vu-chuyen-nha-tron-goi a dit :

Heya are using Wordpress for your site platform? I'm new to the blog world but I'm trying to get started and create my own. Do you require
any coding expertise to make your own blog? Any help
would be really appreciated!

#20 noi that no1 a dit :

Wе wish to thank yօu just aѕ before for the lovely ideas
you offereɗ Jeremy when prеparing her own post-graduate reseaгϲh and,
most importantly, regarding providing аll of the ideas in a single blog post.
Provided that we had known of уour web-sіte a year ago, we might have been rescuеd from the
needless measures we were participating in. Thаnks to you.

#21 soi cau mien bac hom nay mien phi a dit :

We are a group of volunteers and starting a new scheme іn oսr community.
Your web site offered us ᴡith սseful info to work on. Yօu've done ɑn impressive activity and оur
entіre community ѕhall be grateful to ʏou.

#22 netflix vpn reviews a dit :

I have read so many posts on the topic of the blogger lovers however this post is truly a nice paragraph, keep it
up.

Écrire un commentaire

Quelle est la dernière lettre du mot jeomu ? :