• python脚本(渗透测试)


    python爬取edusrc

    通过此脚本,可以爬取edusrc的目标信息,生成目标字典,为下一步开发自动化测试工具做准备

    1. import queue
    2. import threading
    3. import time
    4. import requests
    5. from bs4 import BeautifulSoup
    6. import re
    7. def get_edu_name():
    8. while not q.empty():
    9. x=q.get()
    10. url='https://src.sjtu.edu.cn/rank/firm/0/?page=%s'%str(x)
    11. try:
    12. s=requests.get(url).text
    13. print('->正在获取第%s页内容'%x)
    14. soup=BeautifulSoup(s,'lxml')
    15. edu1=soup.find_all('tr')
    16. for i in range(1,len(edu1)):
    17. edu=edu1[i].a.string
    18. print(edu)
    19. with open('eduName.txt', 'a+') as f:
    20. f.write(edu + '\n')
    21. f.close()
    22. except Exception as e:
    23. time.sleep(1)
    24. pass
    25. if __name__=='__main__':
    26. q = queue.Queue()
    27. for i in range(1,209):
    28. q.put(i)
    29. for i in range(10):
    30. t=threading.Thread(target=get_edu_name)
    31. t.start()

    python爆破shadow

     crypt这个模块只能在Linux下才能运行,此外,密码文件需要自己定义,爆破的成功率取决于字典的强大

    1. import crypt
    2. def testpass(shadow):
    3. user=shadow.split(":")[0] #获得用户名
    4. cryptpass=shadow.split(":")[1] #获得加密字段
    5. salt=cryptpass[0:cryptpass.rindex("$")] #获取盐值
    6. passdict=open("key.txt",'r')
    7. for passwd in passdict.readlines():
    8. passwd=passwd.strip('\n')
    9. cryptpasswd=crypt.crypt(passwd,salt) #将密码中的值和盐值一起加密
    10. if(cryptpasswd==cryptpass):
    11. print("[+]Found Password:", user, ":", passwd)
    12. def main():
    13. shadowfile=open('/etc/shadow')
    14. for shadow in shadowfile.readlines():
    15. if "$" in shadow:
    16. testpass(shadow)
    17. if __name__ == '__main__':
    18. main()

    实验效果

    python联动AWVS 

    这里需要将API key和url等替换成自己的

    1. import requests,json
    2. api_add_url = "https://localhost:3443/api/v1/targets"
    3. headers = {
    4. 'X-Auth': '1986ad8c0a5b3df4d7028d5f3c06e936cc4ce04ea3d4b4ad69123594ad34b4c31',
    5. 'Content-type': 'application/json'
    6. }
    7. data = '{"address":"http://vulnweb.com/","description":"create_by_reaper","criticality":"10"}'
    8. r = requests.post(url=api_add_url, headers=headers, data=data,verify=False).json()
    9. target_id=r['target_id']
    10. print(r)
    11. api_run_url='https://localhost:3443/api/v1/scans'
    12. headers = {
    13. 'X-Auth': '1986ad8c0a5b3df4d7028d5f3c06e936cc4ce04ea3d4b4ad69123594ad34b4c31',
    14. 'Content-type': 'application/json'
    15. }
    16. data = '{"profile_id":"11111111-1111-1111-1111-111111111111","schedule":{"disable":false,"start_date":null,"time_sensitive":false},"target_id":"%s"}'% target_id
    17. r = requests.post(url=api_run_url, headers=headers, data=data, verify=False).json()
    18. print(r)

    python联动sqlmap

    实现自动添加任务进行sqlmap扫描

    1. import requests,json
    2. """
    3. python sqlmapapi.py -s 启动sqlmap-api服务
    4. @get("/task/new") 1.创建新任务记录任务ID
    5. @post("/option/<taskid>/set") 2.设置任务ID扫描信息
    6. @post("/scan/<taskid>/start") 3.开始扫描对应ID任务
    7. @get("/scan/<taskid>/status") 4.读取扫描状态判断结果
    8. @get("/scan/<taskid>/data") 5.扫描结果查看
    9. @get("/task/<taskid>/delete") 6.结束删除ID
    10. """
    11. def new_id():
    12. url='http://127.0.0.1:8775/task/new'
    13. headers = {'Content-Type': 'application/json'}
    14. res=requests.get(url,headers=headers).json()
    15. if res['success'] is True:
    16. print('->1.创建新任务记录任务ID: '+res['taskid'])
    17. return res['taskid']
    18. def set_id(id,scanurl):
    19. url = 'http://127.0.0.1:8775/option/%s/set'%id
    20. data={
    21. 'url':scanurl
    22. }
    23. headers = {'Content-Type': 'application/json'}
    24. res = requests.post(url,data=json.dumps(data),headers=headers).json()
    25. if res['success'] is True:
    26. print('->2设置任务ID扫描信息成功 '+id+'\n'+'->3设置目标url扫描信息成功url: '+scanurl)
    27. def start_id(id,scanurl):
    28. url='http://127.0.0.1:8775/scan/%s/start'%id
    29. data = {
    30. 'url': scanurl
    31. }
    32. headers = {'Content-Type': 'application/json'}
    33. res=requests.post(url,data=json.dumps(data),headers=headers).json()
    34. if res['success'] is True:
    35. print('->4启动任务ID扫描信息成功 '+id+'url: '+scanurl)
    36. def status_id(id):
    37. url='http://127.0.0.1:8775/scan/%s/status'%id
    38. headers = {'Content-Type': 'application/json'}
    39. print('->5开始扫描 ID:'+id)
    40. while True:
    41. res=requests.get(url,headers=headers).json()
    42. if res['status']=='running':
    43. continue
    44. else:
    45. print('扫描完成 ID:'+id)
    46. break
    47. def data_id(id,scanurl):
    48. url='http://127.0.0.1:8775/scan/%s/data'%id
    49. headers = {'Content-Type': 'application/json'}
    50. resp = requests.get(url, headers=headers)
    51. res=requests.get(url,headers=headers).json()
    52. if res['data'][0]['status']==1:
    53. print('->6存在注入 ' + id + 'url: ' + scanurl)
    54. print('正在写入sqlresult.txt')
    55. with open('sqlresult.txt','a+') as f:
    56. f.write(resp.text)
    57. f.write('\n'+'---------------------------------')
    58. f.close()
    59. print('写入完成')
    60. def del_id(id,scanurl):
    61. url='http://127.0.0.1:8775/task/%s/delete'%id
    62. headers = {'Content-Type': 'application/json'}
    63. res=requests.get(url,headers=headers).json()
    64. if res['success'] is True:
    65. print('->7删除任务信息成功 '+id+'url: '+scanurl)
    66. if __name__ == '__main__':
    67. for url in open('vulnweb.txt'):
    68. id=new_id()
    69. set_id(id,url.replace('\n',''))
    70. start_id(id,url.replace('\n',''))
    71. start_id(id,url.replace('\n',''))
    72. status_id(id)
    73. data_id(id,url)
    74. del_id(id,url)
    75. print('------------------------------------')

    python联动Xray并实现微信推送

    这里需要用到server酱

    1. import time
    2. from flask import Flask, request
    3. import requests
    4. app = Flask(__name__)
    5. @app.route('/webhook', methods=['POST'])
    6. def test():
    7. wx = 'https://sctapi.ftqq.com/SCT222793TLvGVTGB4O6fpNbfmt7IBwEy.send?title=xray'
    8. try:
    9. vuln = request.json
    10. type = vuln.get('type') # 使用.get()方法可以避免在键不存在时抛出KeyError
    11. plugin = vuln.get('data', {}).get('plugin')
    12. url = vuln.get('data', {}).get('target',{}).get('url')
    13. content = """## Xray发现了新漏洞
    14. 发现漏洞类型:{type}
    15. 发现漏洞插件:{plugin}
    16. 发现漏洞url:{url}
    17. """.format(type=type, plugin=plugin, url=url)
    18. print(content)
    19. data = {
    20. 'desp': content
    21. }
    22. print(data)
    23. requests.post(wx, data=data)
    24. return 'ok'
    25. except Exception as e:
    26. time.sleep(1)
    27. pass
    28. if __name__ == '__main__':
    29. app.run()

  • 相关阅读:
    Unity中Shader光强与环境色
    【深入浅出Spring原理及实战】「IOC容器初始化」彻底让你明白和理解运行原理和源码流程
    安装MathType
    (数据结构与算法)LeetCode刷题笔记2-0005:最长回文子串
    Thread类的用法
    通过Dynamo批量打印PDF图纸
    每日一题 2034. 股票价格波动(中等,有序队列)
    AIGC重塑金融:AI大模型驱动的金融变革与实践
    使用CEF(七)详解macOS下基于CEF的多进程应用程序CMake项目搭建
    Linux 中解压不同的压缩文件用到不同的命令详解
  • 原文地址:https://blog.csdn.net/weixin_56537388/article/details/132969170