[关闭]
@cyysu 2017-10-17T08:31:43.000000Z 字数 2109 阅读 818

python混淆脚本

  • 时间:2017年10月17日
  • 作者:Kali
  • 邮箱:cyysu.github.io@gmail.com/2869905223@qq.com/微信lwyx1413
  • 版本:4.0
  • 描述:Python下的混淆脚本,将一些函数变成你想要的字符串

脚本编写


脚本内容

  1. #! /usr/bin/env python
  2. #coding=utf-8
  3. import hashlib
  4. import random
  5. import os
  6. import sys
  7. ###############################
  8. # Describe : compuse scripte V2.0
  9. # Author: mj dz chenyuan
  10. # Create Date: 2017-08-26
  11. # Modify Date: 2017-08-26
  12. ###############################
  13. # set your compuse variables or functions name !!! you can't compuse system function !!!!!!!!
  14. raw_name_list = ["object_device1","transactionId","controller_longPoll", "requestdata","subscriptionId","method","object_device2","tiger_device","virtual_device","get_device","connectdevice","reqdata","getSettingsGroup","subscribe"]
  15. new_name_list = []
  16. alphabet = ["a", "b", "c", "d", "e", "f", "g",
  17. "h", "i", "j", "k", "l", "m", "n", "o", "p", "q",
  18. "r", "s", "t", "u", "v", "w", "x", "y", "z",
  19. ]
  20. def create_new_name() :
  21. m = hashlib.md5()
  22. #生成随机变量名
  23. for raw_name in raw_name_list:
  24. m.update(raw_name)
  25. #生成一个16位的字串
  26. temp_name = m.hexdigest()[0:16]
  27. #合法名称校验
  28. #强制以字母作为变量/方法名的开头
  29. if temp_name[0].isdigit():
  30. initial = random.choice(alphabet)
  31. temp_name = initial + temp_name
  32. temp_name = temp_name[0:16]
  33. #不能重名
  34. while(1):
  35. if temp_name in new_name_list :
  36. initial = random.choice(alphabet)
  37. temp_name = initial + temp_name
  38. temp_name = temp_name[0:16]
  39. else:
  40. new_name_list.append(temp_name)
  41. break
  42. def confuse_file(path_filename):
  43. file_content = ""
  44. f = file(path_filename)
  45. # if no mode is specified, 'r'ead mode is assumed by default
  46. while True:
  47. line = f.readline()
  48. if len(line) == 0: # Zero length indicates EOF
  49. break
  50. name_index = 0
  51. for raw_name in raw_name_list:
  52. the_new_name = new_name_list[name_index]
  53. line = line.replace(raw_name, the_new_name)
  54. name_index += 1
  55. file_content += line
  56. f.close()
  57. f = file(path_filename, 'w')
  58. f.write(file_content)
  59. f.close()
  60. def confuse_all():
  61. dir = os.getcwd()
  62. for root, dirs, filename in os.walk(dir):
  63. for file in filename:
  64. path_filename = os.path.join(root, file)
  65. if path_filename.endswith('.py'):
  66. #
  67. if path_filename.split("/",5)[-1]==sys.argv[0]:
  68. pass
  69. else:
  70. confuse_file(path_filename)
  71. print "Confuse File: ", path_filename
  72. # main functions
  73. if __name__=="__main__":
  74. create_new_name()
  75. confuse_all()
  76. print "Start Confuse ...."
  77. for j in range(0, len(raw_name_list)) :
  78. print raw_name_list[j] , " --> " , new_name_list[j]
  79. print "Confuse Complete !"

打赏

                    支付宝                                                         微信

微信与支付宝支付

添加新批注
在作者公开此批注前,只有你和作者可见。
回复批注