C ++ implements simulated logon-Send the post form information package

Source: Internet
Author: User
Tags socket error

C ++ implements simulated logon-Send the post form information package

 

Test URL ip: 222.73.24.32

Test account: lzh_2

Password 123456789

 

First, determine the information of the submission form. I captured the post package using the packet capture tool, and then wrote a program to simulate the sending process, realizing the login process.

 

Note:

1. The packet capture information must be sent, and even the number of spaces and line breaks must be the same;

2. The simulated logon webpage does not have a verification code;

 

Code:

 

// Post sends form information to simulate logon # include
 
  
# Include
  
   
# Include
   
    
# Include
    
     
# Include
     
      
# Include
      
        # Pragma comment (lib, ws2_32.lib) # define max 20480 using namespace std; int main () {int num, sum; SOCKET s; WSADATA wsa; struct sockaddr_in serv; char sndBuf [max], rcvBuf [max]; WSAStartup (MAKEWORD (2, 1), & wsa); if (s = socket (AF_INET, SOCK_STREAM, 0 )) <0) {perror (socket error !); Exit (1);} memset (& serv, 0, sizeof (serv); serv. sin_family = AF_INET; serv. sin_port = htons (80); // serv. sin_addr.s_addr = * (int *) * host_addr-> h_addr_list); serv. sin_addr.S_un.S_addr = inet_addr (222.73.24.32); if (connect (s, (struct sockaddr *) & serv, sizeof (serv) <0) {perror (connet error !); Exit (1);} memset (sndBuf, 0, max); memset (rcvBuf, 0, max); // header information strcat (sndBuf, POST); strcat (sndBuf, /inc/Check. asp HTTP/1.1); strcat (sndBuf, x-requested-with: XMLHttpRequest); strcat (sndBuf, Accept-Language: zh-cn); strcat (sndBuf, Referer: http://user.exam8.com/user_login.asp); strcat (sndBuf,); strcat (sndBuf, Accept: */*); strcat (sndBuf, Content-Type: application/x-www-form-urlencoded ); strcat (sndBuf, Accept-Encoding: gzip, deflate); strcat (sndBuf, User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.1; WOW64; Trident/5.0; SLCC2 ;. net clr 2.0.50727 ;. net clr 3.5.30729 ;. net clr 3.0.30729; eSobiSubscriber 1.0.0.40; MAAR ;. NET4.0C ;. NET4.0E; Maxthon/3.0); strcat (sndBuf, Host: user.exam8.com); strcat (sndBuf, Content-Length: 61); strcat (sndBuf, Connection: Keep-Alive ); strcat (sndBuf, Cache-Contr Ol: no-cache); strcat (sndBuf, Cookie: bytes = 1415795254,1415797440; referrer = http % 3A // export CNZZDATA89268 = cnzz_eid % 3D1936228237-1 Listen 277587-http % 253A % 252F % 252Fuser.exam8.com % 252F % 26 ntime % 3D1415871209; aspsessionid1_tbsdt = Hangzhou); strcat (sndBuf,); strcat (sndBuf, action = login & LoginUserName = lzh_2 & LoginUserPassword = 123456789 &); puts (sndBuf); if (num = send (s, sndBuf, max, 0) <0) {perror (send error !); Exit (1);} puts (send success !); Sum = recv (s, rcvBuf, max-1, 0); // If rcvBuf's storage space is reduced, copyif (sum> 0) {puts (OK !); Printf (% s, rcvBuf);} puts (read success !); Closesocket (s); system (pause); WSACleanup (); return 0 ;}
      
     
    
   
  
 

Running result:

 

1. send information

 

2. Message returned after successful sending:

 

3. Information returned after Successful Logon:

 

4. Enter the wrong user name or password:

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.