Python scripts to find webshells

Source: Internet
Author: User
This article mainly introduces how to use python scripts to find webshells. It is a very practical function. If you need it, refer to the following article to describe a python code for searching webshell scripts, in addition to the webshell search function, the white list function and the function of sending email alerts when malicious code is found are available. If you are interested, you can test the function by yourself.

The specific function code is as follows:

#! /Usr/bin/env python #-*-coding: UTF-8-*-import osimport sysimport reimport smtplib # Set the email fromaddr = "smtp.qq.com" toaddrs = ["voilet@qq.com"] username = "voilet" password = "xxxxxx" # Set the whitelist pass_file = ["api_ucenter.php"] # define the email sending function def sendmail (toaddrs, sub, content): 'sending mail module '# Add the From: and To: headers at the start! Msg = ("From: % s \ r \ nTo: % s \ r \ nSubject: % s \ r \ n" % (fromaddr ,",". join (toaddrs), sub) msg + = content server = smtplib. SMTP ('mail .funshion.com ', 25,) server. login (username, password) server. sendmail (fromaddr, toaddrs, msg) server. quit () # Set the search signature rulelist = ['(\ $ _ (GET | POST | REQUEST )\[. {0, 15} \] \ (\ $ _ (GET | POST | REQUEST )\[. {200} \] \) ',' (base64_decode \ ([\ '"] [\ w \ +/=] {,} [\'"] \) ', 'eval \ (base64_decod E \ (',' (eval \ (\$ _ (POST | GET | REQUEST )\[. {0, 15} \] \) ',' (assert \ (\ $ _ (POST | GET | REQUEST )\[. {} \] \) ',' (\ $ [\ w _] {} \ (\ $ _ (POST | GET | REQUEST )\[. {0, 15} \] \) ',' (wscript \. shell) ',' (gethostbyname \ () ',' (cmd \. exe) ',' (shell \. application) ',' (events \ s + and \ s + settings) ',' (system32) ',' (serv-u) ',' (Elevation of Privilege )', '(phpspy)', '(backdoor)', '(webshell)', '(Program \ s + Files)', 'www .phpdp.com ', 'phpdp ', 'php shield ', 'decryptio N', 'ca3tie1 ', 'gif 89a', 'ikfbiluvm0vcjd \/APDolOjtW0tgeKAwA', '\ 'E \'\. \ 'v \'\. \ 'a \'\. \ 'l \ '',] def Scan (path): for root, dirs, files in OS. walk (path): for filespath in files: isover = False if '. 'In filespath: ext = filespath [(filespath. rindex ('. ') + 1):] if ext = 'php' and filespath not in pass_file: file = open (OS. path. join (root, filespath) filestr = file. read () file. close () for rule in rulelist: result = Re. compile (rule ). findall (filestr) if result: print 'file:' + OS. path. join (root, filespath) print 'malicious code: '+ str (result [0]) print' \ n \ n' sendmail (toaddrs, "value-added malicious code found ", 'File: '+ OS. path. join (root, filespath) + "\ n" + 'malicious code: '+ str (result [0]) breaktry: if OS. path. lexists ("/home/web_root/"): print ('\ n start scanning:' + "/home/web_root/") print ('suspicious files ') print ('##################################### ###') scan ("/home/web_root /") Print ('prompt: Scan completed --~ ') Else: print' prompt: the specified scan directory does not exist --- 'failed t IndexError: print "Please specify the scan file directory"

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.