nmap姒傚康鍙婂姛鑳?/h1>
姒傚康
NMap锛屼篃灏辨槸Network Mapper锛屾渶鏃╂槸Linux涓嬬殑缃戠粶鎵弿鍜?a href="http://baike.baidu.com/view/282229.htm" target="_blank">鍡呮帰宸ュ叿鍖呫€?/p>
nmap鏄竴涓綉缁滆繛鎺ョ鎵弿杞欢锛岀敤鏉ユ壂鎻忕綉涓婄數鑴戝紑鏀剧殑缃戠粶杩炴帴绔€傜‘瀹氬摢浜涙湇鍔¤繍琛屽湪鍝簺杩炴帴绔紝骞朵笖鎺ㄦ柇璁$畻鏈鸿繍琛屽摢涓搷浣滅郴缁燂紙杩欐槸浜︾О fingerprinting锛夈€傚畠鏄綉缁滅鐞嗗憳蹇呯敤鐨勮蒋浠朵箣涓€锛屼互鍙婄敤浠ヨ瘎浼扮綉缁滅郴缁熷畨鍏ㄣ€?/p>
姝e澶у鏁拌鐢ㄤ簬缃戠粶瀹夊叏鐨勫伐鍏凤紝nmap 涔熸槸涓嶅皯榛戝鍙婇獓瀹紙鍙堢О鑴氭湰灏忓瓙锛夌埍鐢ㄧ殑宸ュ叿 銆傜郴缁熺鐞嗗憳鍙互鍒╃敤nmap鏉ユ帰娴嬪伐浣滅幆澧冧腑鏈粡鎵瑰噯浣跨敤鐨勬湇鍔″櫒锛屼絾鏄粦瀹細鍒╃敤nmap鏉ユ悳闆嗙洰鏍囩數鑴戠殑缃戠粶璁惧畾锛屼粠鑰岃鍒掓敾鍑荤殑鏂规硶銆?/p>
Nmap 甯歌璺熻瘎浼扮郴缁熸紡娲炶蒋浠?a href="http://baike.baidu.com/view/1382512.htm" target="_blank">Nessus 娣蜂负涓€璋堛€侼map 浠ラ殣绉樼殑鎵嬫硶锛岄伩寮€闂叆妫€娴嬬郴缁熺殑鐩戣锛屽苟灏藉彲鑳戒笉褰卞搷鐩爣绯荤粺鐨勬棩甯告搷浣溿€?/p>
Nmap 鍦?a href="http://baike.baidu.com/subview/6918/8159699.htm" target="_blank" data-lemmaid="34564">榛戝甯濆浗(The Matrix)涓紝杩炲悓SSH1鐨?2浣嶅厓寰幆鍐椾綑鏍¢獙婕忔礊锛岃宕斿Ξ钂傜敤浠ュ叆渚靛彂鐢电珯鐨勮兘婧愮鐞嗙郴缁熴€?/p>
鍔熻兘
鍩烘湰鍔熻兘鏈変笁涓紝涓€鏄帰娴嬩竴缁勪富鏈烘槸鍚﹀湪绾匡紱鍏舵鏄壂鎻?涓绘満绔彛锛?a href="http://baike.baidu.com/view/282229.htm" target="_blank">鍡呮帰鎵€鎻愪緵鐨勭綉缁滄湇鍔★紱杩樺彲浠ユ帹鏂富鏈烘墍鐢ㄧ殑鎿嶄綔绯荤粺 銆侼map鍙敤浜庢壂鎻忎粎鏈変袱涓妭鐐圭殑LAN锛岀洿鑷?00涓妭鐐逛互涓婄殑缃戠粶銆侼map 杩樺厑璁哥敤鎴峰畾鍒舵壂鎻忔妧宸с€傞€氬父锛屼竴涓畝鍗曠殑浣跨敤ICMP鍗忚鐨刾ing鎿嶄綔鍙互婊¤冻涓€鑸渶姹傦紱涔熷彲浠ユ繁鍏ユ帰娴婾DP鎴栬€匱CP绔彛锛岀洿鑷?a href="http://baike.baidu.com/view/23880.htm" target="_blank">涓绘満鎵€ 浣跨敤鐨勬搷浣滅郴缁燂紱杩樺彲浠ュ皢鎵€鏈夋帰娴嬬粨鏋滆褰曞埌鍚勭鏍煎紡鐨勬棩蹇椾腑锛?渚涜繘涓€姝ュ垎鏋愭搷浣溿€?/p>
杩涜ping鎵弿锛屾墦鍗板嚭瀵规壂鎻忓仛鍑哄搷搴旂殑涓绘満,涓嶅仛杩涗竴姝ユ祴璇?濡?a href="http://baike.baidu.com/view/700108.htm" target="_blank">绔彛鎵弿鎴栬€呮搷浣滅郴缁熸帰娴?锛?/p>
nmap -sP 192.168.1.0/24
浠呭垪鍑烘寚瀹氱綉缁滀笂鐨勬瘡鍙颁富鏈猴紝涓嶅彂閫佷换浣?a href="http://baike.baidu.com/view/175122.htm" target="_blank">鎶ユ枃鍒扮洰鏍囦富鏈猴細
nmap -sL 192.168.1.0/24
鎺㈡祴鐩爣涓绘満寮€鏀剧殑绔彛锛屽彲浠ユ寚瀹氫竴涓互閫楀彿鍒嗛殧鐨勭鍙e垪琛?濡?PS22锛?3锛?5锛?0)锛?/p>
nmap -PS 192.168.1.234
浣跨敤UDP ping鎺㈡祴涓绘満锛?/p>
nmap -PU 192.168.1.0/24
浣跨敤棰戠巼鏈€楂樼殑鎵弿閫夐」锛歋YN鎵弿,鍙堢О涓哄崐寮€鏀炬壂鎻忥紝瀹冧笉鎵撳紑涓€涓畬鍏ㄧ殑TCP杩炴帴锛屾墽琛屽緱寰堝揩锛?/p>
nmap -sS 192.168.1.0/24
nmap瀹夎
鏈枃浠inux Ubuntu16.04涓轰緥锛屾渶鍚庝富瑕佺敤python鎿嶄綔
1. 鍏堝畨瑁卬map
sudo apt-get install nmap
2.鍐嶅畨瑁卲ython-nmap
sudo pip install python-nmap
瀹夎瀹屼箣鍚巔ython瀵煎叆nmap娴嬭瘯楠岃瘉鏄惁鎴愬姛
root@LiDebin:~# python Python 2.7.12 (default, Jul 1 2016, 15:12:24) [GCC 5.4.0 20160609] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import nmap
python鎿嶄綔nmap
1.绠€鍗曠殑灏忔渚?/p>
鍒涘缓PortScanner瀹炰緥锛岀劧鍚庢壂鎻?59.239.210.26杩欎釜IP鐨?0-443绔彛銆?/p>
import nmap nm = nmap.PortScanner() ret = nm.scan(鈥?15.239.210.26鈥?鈥?0鈥? print ret 杩斿洖鏍煎紡濡備笅: {鈥榥map鈥? {鈥榮canstats鈥? {鈥榰phosts鈥? 鈥?鈥? 鈥榯imestr鈥? 鈥楾ue Oct 25 11:30:47 2016鈥? 鈥榙ownhosts鈥? 鈥?鈥? 鈥榯otalhosts鈥? 鈥?鈥? 鈥榚lapsed鈥? 鈥?.11鈥榼, 鈥榮caninfo鈥? {鈥榯cp鈥? {鈥榮ervices鈥? 鈥?0鈥? 鈥榤ethod鈥? 鈥榗onnect鈥榼}, 鈥榗ommand_line鈥? 鈥榥map -oX - -p 20 -sV 115.239.210.26鈥榼, 鈥榮can鈥? {鈥?15.239.210.26鈥? {鈥榮tatus鈥? {鈥榮tate鈥? 鈥榰p鈥? 鈥榬eason鈥? 鈥榮yn-ack鈥榼, 鈥榟ostnames鈥? [{鈥榯ype鈥? 鈥樷€? 鈥榥ame鈥? 鈥樷€榼], 鈥榲endor鈥? {}, 鈥榓ddresses鈥? {鈥榠pv4鈥? 鈥?15.239.210.26鈥榼, 鈥榯cp鈥? {20: {鈥榩roduct鈥? 鈥樷€? 鈥榮tate鈥? 鈥榝iltered鈥? 鈥榲ersion鈥? 鈥樷€? 鈥榥ame鈥? 鈥榝tp-data鈥? 鈥榗onf鈥? 鈥?鈥? 鈥榚xtrainfo鈥? 鈥樷€?
鈥榬eason鈥? 鈥榥o-response鈥? 鈥榗pe鈥? 鈥樷€榼 } } } }
2.鍐呯疆鏂规硶锛?/p>
杩樺彲浠ユ墦鍗板嚭绠€鍗曠殑淇℃伅
import nmap nm = nmap.PortScanner() print nm.scaninfo() # {u鈥榯cp鈥? {鈥榮ervices鈥? u鈥?0-443鈥? 鈥榤ethod鈥? u鈥榮yn鈥榼} print nm.command_line() # u鈥榥map -oX - -p 20-443 -sV 115.239.210.26鈥?
鏌ョ湅鏈夊灏戜釜host
print nm.all_hosts() # [u鈥?15.239.210.26鈥榏
鏌ョ湅璇ost鐨勮缁嗕俊鎭?/p>
nm[鈥?15.239.210.26鈥榏
鏌ョ湅璇ost鍖呭惈鐨勬墍鏈夊崗璁?/p>
nm[鈥?15.239.210.26鈥榏.all_protocols()
鏌ョ湅璇ost鐨勫摢浜涚鍙f彁渚涗簡tcp鍗忚
nm[鈥?15.239.210.26鈥榏[鈥榯cp鈥榏 nm[鈥?15.239.210.26鈥榏[鈥榯cp鈥榏.keys()
鏌ョ湅璇ョ鍙f槸鍚︽彁渚涗簡tcp鍗忚
nm[鈥?15.239.210.26鈥榏.has_tcp(21)
杩樺彲浠ュ儚杩欐牱璁剧疆nmap鎵ц鐨勫弬鏁?/p>
nm.scan(hosts=鈥?92.168.1.0/24鈥? arguments=鈥?n -sP -PE -PA21,23,80,3389鈥?
鏇村鎿嶄綔璇疯繘瀹樼綉http://xael.org/pages/python-nmap-en.html
瀹為獙妗堜緥
妫€娴嬪唴缃戞満鍣ㄧ鍙?/p>
1.瀹氫箟鍑芥暟搴搈ytools.py
#-*- coding:utf-8 -*- import smtplib from email.mime.text import MIMEText from email.header import Header def sendemail(sender,receiver,subject,content,smtpserver,smtpuser,smtppass): msg = MIMEText(content,鈥榟tml鈥?鈥榰tf-8鈥?#涓枃闇€鍙傛暟‘utf-8鈥橈紝鍗曞瓧鑺傚瓧绗︿笉闇€瑕? msg[鈥楽ubject鈥榏 = Header(subject, 鈥榰tf-8鈥? msg[鈥楩rom鈥榏 = 鈥?lt;%s>鈥?% sender msg[鈥楾o鈥榏 = ";".join(receiver) try: smtp = smtplib.SMTP() smtp.connect(smtpserver) smtp.login(smtpuser, smtppass) smtp.sendmail(sender, receiver, msg.as_string()) smtp.quit() except Exception,e: print e
2. 瀹炵幇绔彛鎵弿鐨勭▼搴忥紝鍗曠嚎绋嬬増鏈琻mscan.py
# !/usr/bin/python # -*- coding:utf-8 -*- import nmap import re import mytools as tool import sys reload(sys) sys.setdefaultencoding(鈥榰tf8鈥? def nmScan(hostlist, portrange, whitelist): p = re.compile("^(d*)-(d*)$") if type(hostlist) != list: help() portmatch = re.match(p, portrange) if not portmatch: help() l = [] for host in hostlist: result = 鈥樷€? nm = nmap.PortScanner() tmp = nm.scan(host, portrange) result = result + "<h2>ip鍦板潃:%s 涓绘満鍚?[%s] ...... %s</h2><hr>" % ( host, tmp[鈥榮can鈥榏[host][鈥榟ostname鈥榏, tmp[鈥榮can鈥榏[host][鈥榮tatus鈥榏[鈥榮tate鈥榏) try: ports = tmp[鈥榮can鈥榏[host][鈥榯cp鈥榏.keys() except KeyError, e: if whitelist: whitestr = 鈥?鈥?join(whitelist) result = result + "鏈壂鍒板紑鏀剧鍙?璇锋鏌?s绔彛瀵瑰簲鐨勬湇鍔$姸鎬? % whitestr else: result = result + "鎵弿缁撴灉姝e父锛屾棤鏆存紡绔彛" for port in ports: info = 鈥樷€? if port not in whitelist: info = 鈥?lt;strong><font color=red>Alert:闈為鏈熺鍙?lt;/font><strong> 鈥? else: info = 鈥?lt;strong><font color=green>Info:姝e父寮€鏀剧鍙?lt;/font><strong> 鈥? portinfo = "%s <strong>port</strong> : %s <strong>state</strong> : %s <strong>product<strong/> : %s <br>" % ( info, port, tmp[鈥榮can鈥榏[host][鈥榯cp鈥榏[port][鈥榮tate鈥榏, tmp[鈥榮can鈥榏[host][鈥榯cp鈥榏[port][鈥榩roduct鈥榏) result = result + portinfo l.append([host, str(result)]) return l def help(): print "Usage: nmScan([鈥?27.0.0.1鈥?],鈥?-65535鈥?" if __name__ == "__main__": hostlist = [鈥?0.10.10.10鈥? 鈥?0.10.10.11鈥榏 portrange = 鈥?-65535鈥? whitelist = [80, 443] l = nmScan(hostlist, portrange, whitelist) sender = 鈥?5501664@qq.com鈥? receiver = [鈥榸hangyanlin8851@163.com鈥? 鈥?77986976@qq.com鈥榏 subject = 鈥樻湇鍔″櫒绔彛鎵弿鈥? smtpserver = 鈥榮mtp.exmail.qq.com鈥? smtpuser = 鈥榸hangyanlin8851@163.cn鈥? smtppass = 鈥榣inuxidc163鈥? mailcontent = 鈥樷€? for i in range(len(l)): mailcontent = mailcontent + l[i][1] tool.sendemail(sender, receiver, subject, mailcontent, smtpserver, smtpuser, smtppass)
3.澶氱嚎绋嬬増鏈?/p>
# !/usr/bin/python # -*- coding:utf-8 -*- import nmap import re import mytools as tool import sys from multiprocessing import Pool from functools import partial reload(sys) sys.setdefaultencoding(鈥榰tf8鈥? def nmScan(host, portrange, whitelist): p = re.compile("^(d*)-(d*)$") # if type(hostlist) != list: # help() portmatch = re.match(p, portrange) if not portmatch: help() if host == 鈥?21.42.32.172鈥? whitelist = [25, ] result = 鈥樷€? nm = nmap.PortScanner() tmp = nm.scan(host, portrange) result = result + "<h2>ip鍦板潃:%s 涓绘満鍚?[%s] ...... %s</h2><hr>" % ( host, tmp[鈥榮can鈥榏[host][鈥榟ostname鈥榏, tmp[鈥榮can鈥榏[host][鈥榮tatus鈥榏[鈥榮tate鈥榏) try: ports = tmp[鈥榮can鈥榏[host][鈥榯cp鈥榏.keys() for port in ports: info = 鈥樷€? if port not in whitelist: info = 鈥?lt;strong><font color=red>Alert:闈為鏈熺鍙?lt;/font><strong> 鈥? else: info = 鈥?lt;strong><font color=green>Info:姝e父寮€鏀剧鍙?lt;/font><strong> 鈥? portinfo = "%s <strong>port</strong> : %s <strong>state</strong> : %s <strong>product<strong/> : %s <br>" % ( info, port, tmp[鈥榮can鈥榏[host][鈥榯cp鈥榏[port][鈥榮tate鈥榏, tmp[鈥榮can鈥榏[host][鈥榯cp鈥榏[port][鈥榩roduct鈥榏) result = result + portinfo except KeyError, e: if whitelist: whitestr = 鈥?鈥?join(whitelist) result = result + "鏈壂鍒板紑鏀剧鍙?璇锋鏌?s绔彛瀵瑰簲鐨勬湇鍔$姸鎬? % whitestr else: result = result + "鎵弿缁撴灉姝e父锛屾棤鏆存紡绔彛" return result def help(): print "Usage: nmScan([鈥?27.0.0.1鈥?],鈥?-65535鈥?" return None if __name__ == "__main__": hostlist = [鈥?0.10.10.10鈥? 鈥?0.10.10.11鈥榏 portrange = 鈥?-65535鈥? whitelist = [80, 443] l = nmScan(hostlist, portrange, whitelist) sender = 鈥?5501664@qq.com鈥? receiver = [鈥榸hangyanlin8851@163.com鈥? 鈥?77986976@qq.com鈥榏 subject = 鈥樻湇鍔″櫒绔彛鎵弿鈥? smtpserver = 鈥榮mtp.exmail.qq.com鈥? smtpuser = 鈥榸hangyanlin8851@163.cn鈥? smtppass = 鈥榣inuxidc163鈥? mailcontent = 鈥樷€? for i in range(len(l)): mailcontent = mailcontent + l[i][1] tool.sendemail(sender, receiver, subject, mailcontent, smtpserver, smtpuser, smtppass)
銆€