C # ticket collection program

Source: Internet
Author: User

Someone asked me to vote last month. I wanted to give him more clicks without writing a program. Although this is against the principle, I should be entertaining ..

 

First

 

 

1. Analysis

Since it is a Web site vote, it is certainly possible to forge an HTTP request to achieve the vote. What needs to be analyzed is what measures the website has taken to prevent ticket swiping. The original vote has been stopped. I will describe it to you.

(1) First of all, this is a public vote for all people, and there is no need to be a limit on their users.

(2) First, press F12 to view network conditions and capture HTTP requests for voting. Click to vote, intercept, and find that it is the Get method. The QuerySting value has a random number, the ID of a candidate, and an unclear value. It is preliminarily estimated that it is restricted by Cookie.

(3) After the vote is cast, click the vote, and the result is displayed: "You have already participated in the vote and can only vote once a day ".

(4). In the Chrome browser, set, set privacy, view the Cookies in the Cookie, find the Cookies of the website, and find an unknown Cookie with the candidate ID. Delete both of them and click vote to display "Vote failed ". Although the vote was not successful, the returned information is different, which indicates that it must be related to cookies.

(5) directly disable the Cookie of the website, and click "Vote failed ".

(6 ). at this time, I carefully looked at the unclear value of QueryString, which is the same as the unclear value in the Cookie. The voting button event should not change, it is estimated that the two will be loaded together when the page is loaded. Then refresh the page and the value changes.

(7). Then, only the Cookie with the candidate ID is deleted, the Cookie is retained, and the voting is successful!

The anti-ticket farming measures for this website are relatively simple. You only need to take a closer look to find this problem. Then I made the first version.

2. Construct an HTTP request

(1). Get SID. Call the long string of unclear values I mentioned above as SID to verify whether the Cookie works.

 

Private string GetSid () {string url = "http://www.xxxxxx.com/xxxx/list-510-1.html"; HttpWebRequest req = (HttpWebRequest) WebRequest. create (url); var res = req. getResponse () as HttpWebResponse; string sid = res. headers. getValues (5) [0]. split ('=') [1]; // extract the value of the first Cookie in Response from Headers.
Return sid;
}

(2) simulate an HTTP request based on the HTTP request captured by the browser

Private HttpWebRequest CreatHttp () {Random rnd = new Random (); string rndstr = rnd. nextDouble (). toString (); // This is a random number that imitates QueryString. The string url =" http://www.xxxxxx.com/xxxx/api.php?op=qgtp&id=32&sid= "+ Sid +" & r = "+ rndstr; HttpWebRequest req = (HttpWebRequest) WebRequest. create (url); CookieCollection cookies = new CookieCollection (); // Add Cookie cookies. add (new Cookie ("xxxxaction", sid, "/rail", "www.peoplerail.com"); cookies. add (new Cookie ("xxxxxxxrand", rndstr, "/rail", "www.peoplerail.com"); // the random number is stored, and the life cycle is only 2 seconds, therefore, I did not find that I wrote the req for the sake of fidelity. cookieContainer = new CookieContainer (); req. cookieContainer. add (cookies); req. method = "GET"; req. userAgent = "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/28.0.1500.95 Safari/537.36"; req. timeout = 10000; req. referer =" http://www.xxxxxx.com/xxxxxx/index.php?m=content&c=index&a=lists&catid=517&page=6 "; Req. keepAlive = true; req. headers. add ("x-requested-with", "XMLHttpRequest"); // all the preceding operations correspond to return req according to the results captured in the browser ;}

(3). Refresh the ticket and observe the ticket refresh status. The number of votes in the returned content is updated to the TextBox.

Private void Go () {HttpWebRequest req = CreatHttp (); var res = req. getResponse () as HttpWebResponse; Stream st = res. getResponseStream (); // read Response StreamReader sr = new StreamReader (st); string result = sr. readToEnd (). toString (); try {textBox1.Text = result. split (':') [1]. split ('<') [0]; // obtain the number of votes from the returned content} catch {timer1.Stop (); label2.Text = "suspend ticket Flushing ";}}

 

 

 

(4). Set the loop. If a request is sent through the For loop, the loop is completed several hundred times, but it has not been reflected yet. If Sleep () is used in the middle, the program may sometimes fall into a false state, and the ticket collection cannot be observed in real time. So we use the Timer control that comes with Winform to stop loading the page, set the time interval, and add the above method to the Timer event.

  private void Form1_Load(object sender, EventArgs e)        {            timer1.Stop();            timer1.Interval = 1000;        }

 3. Improvement

After completing the above steps, I tried to brush it. I found that the system would return the "Vote failed, suspected to be a vote" prompt, and adjusted the interval. After two days, it suddenly became difficult. After several analyses, I found that IP address restrictions were added. It is troublesome to find a proxy, so you can use the broadband reconnection method to constantly change the IP address. You can reconnect each record.

Public static string Connect (string UserS, string PwdS) {string arg = @ "rasdial.exe broadband connection" + "" + UserS + "" + PwdS; return InvokeCmd (arg );} public static string Disconnect () {string arg = string. format ("rasdial \" {0} \ "/disconnect", "Broadband connection"); return InvokeCmd (arg);} private static string InvokeCmd (string cmdArgs) {string Tstr = ""; Process p = new Process (); p. startInfo. fileName = "cmd.exe"; p. startInfo. useShellExecute = false; p. startInfo. redirectStandardInput = true; p. startInfo. redirectStandardOutput = true; p. startInfo. redirectStandardError = true; p. startInfo. createNoWindow = true; p. start (); p. standardInput. writeLine (cmdArgs); p. standardInput. writeLine ("exit"); Tstr = p. standardOutput. readToEnd (); p. waitForExit (); p. close (); return Tstr ;}

 

 

There are no comprehensive measures to prevent fake votes for website voting. It can only be said that the anti-gentleman is not a villain. If you want to brush the ticket, you can always find a blank space.

Related Article

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.