How to implement Code Audit with python
This article is about how python implements code auditing. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.
Python Code Audit-Command execution vulnerability (self-written code) 0x00 source code def execute (request): context = {} ip= request.POST.get ("ip") username= request.POST.get ("username") password= request.POST.get ("password") idnex= int (request.POST.get ("index")) current_time=request.POST.get ("time") context = {"ip": ip, "username": username, "password": password "result": False} ippattern= "(25 [0-5] | 2 [0-4]\ d | [0-1]\ d {2} | [1-9]?\ d)\. (25 [0-5] | 2 [0-4]\ d | [0-1]\ d | [1-9]?\ d)\. (25 [0-5] | 2 [0-4]\ d | [0-1]\ d {2} | [1-9]?\ d)\ . (25 [0-5] | 2 [0-4]\ d | [0-1]\ d {2} | [1-9]?\ d) "if (re.match (ippattern) Ip): pass else: context ['error'] = "ip incorrectly formatted" log ("error", "[-]% s ip is error"% (ip)) print ("[-]% s ip malformed"% (ip)) # return render (request,' test.html', context) return HttpResponse (json.dumps (context)) try: length Scripts=executeScript.getScriptNums () if (idnex > length or idnex)