Results 1 to 4 of 4
  1. #1
    schim's Avatar
    Join Date
    May 2010
    Gender
    male
    Location
    My chair
    Posts
    367
    Reputation
    10
    Thanks
    114
    My Mood
    Twisted

    [Help]Problem with bytes

    Hi everyone
    I'm still stuck on the readable part of my winsock application, Apart from being not readable, I'm also unable to print the raw bytes (instead of chars1, ints or huge seemingly random numbers that popup if I print them as a DWORD)

    I've so I decided to see if my packets were legit at all, so I fired up wireshark and anilized the packets, just as all references said these packets all start with the most significant bit ( '00' ) my misterious packets all start with '69' (or E, or other blurish shit depending on how you try to print them)
    And example of a packet dump from my app:

    Code:
    E ܐP@ <gDR^
       P	SP I  TҨyŝCZ$
    YNJտ:
    3%d$Yؐ|,L**RK'[}q1t`߬?"řipa>P$|ֹFqS9nuPGzxHy(Sx7a$%yt8fȪW*3;f{],R}>TtXL'p,-"9Sn*s*)?pai!$/MТ3G#jy ;gfK]iYaAEYTz<j]69QG*p?չS?/gY /BZQ}* =!s[XcW$9>/f3_Vp
    U*Rm[p&GE^Ʌ3FE(TU#?PDo@L=c@BД0+ *Φ+*)iݐ62ƣh+'4dqtU(y3^Il ßܸ3=\+ uI*}DU&Edc`Lqfd{nY׼l@Ʉh=$,O
    I=gc1rTg?	2A>~y`S" A**@O1fŷj:0>[+XwJd3k ]K7hL$Qel߇R9y#ak\a
    ` 8 LCܱR\g-0\U|uhX2|Y
    KmpcA}I^	7Gޤ.I ?XOƸo@3x^88X񓚪7j_m{l <,XuyA`}otbseS*~}V#\>mn?!hoN*$h
    sȴPb1ccm}0Ftp=Vf-P9HBYP`i<n吗ˌ4UAS/FY1+Ob*M"ʺ #lhq(ߴˆ9a끖G%kT&VU4~~Q*v[0
    )mW)>$
    uT+4qxA䊩\S6#Ċ1RAz5PiZait~tM~Őf]VH(l&- ss){?r8]ͷ͇wg*I=DZ0b:xBwR@ ^t2!,ALTvpҟ}{lv+kE]c'ոצ^H/EM0rCCMaIu/>nUXGjcʑ
    8e0T'P~Y	.xoJK^÷, b[*96MǟlEz,,roi<~Le/Z(gU<72֫U^.)e_w&?,`*sK*I*?p8xol6
    I've tried almost everything I could think of but I still cann't print them in pure hex

    For example is I do this:

    cout<<(int)wbuf.buf[ai]<<" "; it somehow menages to print numbers like:
    -104 and -128

    The code I use:

    Main.h
    Code:
    #pragma comment "Main.h"
    
    #define MAX_IP_SIZE 65535
    #define HI_WORD(byte)    (((byte) >> 4) & 0x0F)
    #define LO_WORD(byte)    ((byte) & 0x0F)
    
    #include <iostream>
    #include <winsock2.h>
    #include <iphlpapi.h>
    #include <Mstcpip.h>
    
    #include <string>
    #include <fstream>
    
    #pragma comment(lib, "iphlpapi.lib")
    #pragma comment(lib, "ws2_32.lib")
    
    int Initialize();
    
    using namespace std;

    Capture Trafic.cpp

    Code:
    #include "Main.h"
    
    DWORD dwBytesRet;
    DWORD dwFlags;
    WSADATA wsaData;
    WSABUF wbuf;
    SOCKET s1;
    
    struct sockaddr_in Lip;
    char rcvbuf[MAX_IP_SIZE];
    char ac[80];
    unsigned int optval;
    void* buffer;   // I've also changed the bufer type a few times, no effect
    string str;
    
    ostream& operator<<(ostream& out, const WSADATA& WsaData) {  //Overloading for WSADATA
    	out<< "MaxSockets: "<< WsaData.iMaxSockets << endl;
    	out<< "MaxiMaxUdpDg: "<< WsaData.iMaxUdpDg << endl; 
    	out<< "Description: "<< WsaData.szDescription << endl;
    	out<< "SystemStatus: "<< WsaData.szSystemStatus << endl;
    	out<< "Winsock High Version: "<< WsaData.wHighVersion << endl;
    	out<< "Version: "<< WsaData.wVersion << endl;
    	    return out;  //return exectution
    	}
    
     int Initialize(){
    cout<<"\n\n#########DATA TRAFIC ANILIZING COMPONENT#########\n\n";
    
     if( WSAStartup( MAKEWORD(2, 2), &wsaData ) != NO_ERROR )  //initialize winsock 
        {
            cerr<<"Socket Initialization: wsa startup error\n";
            WSACleanup();
            return -1;
        }
     
     cout<<"WsaStartup succesfully initialized\n\nWSADATA: "<< wsaData <<"\n\n";  //using overloaded operator
     
     // ( s1 = socket( AF_UNSPEC, SOCK_RAW, IPPROTO_ICMP ) ) //initialize raw socket
      
     if (  (s1 = WSASocket(AF_INET, SOCK_RAW,  IPPROTO_IP, NULL, 0, WSA_FLAG_OVERLAPPED) ) == INVALID_SOCKET) { //check for errors
    	 cout << "Invailid socket error: "<< WSAGetLastError() << endl;  // call wsagetlasterror if there are any errors
    	 WSACleanup();
    	 return -2;
     } else {
    	 cout<<"Raw socket is succesfully bound: "<< s1 << endl;
     }
    
    
     
     if (gethostname(ac, sizeof(ac)) == SOCKET_ERROR) {
    	 cout<<"Can not resolve host name: "<< WSAGetLastError() << endl;
    	 WSACleanup();
    	 return -3;
     } else {
    	 cout<<"Host address name is: "<< ac << endl;
     }
    
        struct hostent *phe = gethostbyname(ac);
        if (phe == 0) {
            cerr << "Hostlookup failed" << endl;
            return -4;
        }
    	struct in_addr addr;
    	memcpy(&addr, phe->h_addr_list[0], sizeof(struct in_addr));
    	cout<<"Host address is: "<< inet_ntoa(addr) << endl;
        
    Lip.sin_family = AF_INET;
    Lip.sin_addr.s_addr = inet_addr( inet_ntoa( addr ) );
    Lip.sin_port = htons( 0 );
    
    cout<<"Addres bound to inet_addr! "<< Lip.sin_addr.s_addr <<endl; 
    
    if (  bind(s1,  (SOCKADDR*) &Lip, sizeof(Lip)) != 0 ){
    	cout<<"Cannot bind socket: "<< WSAGetLastError() << endl;
    	 WSACleanup();
    	 closesocket(s1);
    	 return -5;
    } else {
    	cout<<"Socket succesfully bound: "<< s1 << endl;
    }
    
    int i =  WSAIoctl( s1, SIO_RCVALL, &optval, sizeof(optval), NULL, 0, &dwBytesRet, NULL, NULL);
    if( i != 0) {
     cout << "WSAIoctl error: "<< WSAGetLastError() << endl;  // call wsagetlasterror if there are any errors
    	 WSACleanup();
    	 closesocket(s1);
    	 return -6;
    } else{
    cout<<"WSAioctl succesfully called"<<endl;
    }
        
         wbuf.len = MAX_IP_SIZE;
         wbuf.buf = rcvbuf;
         dwFlags  = 0;
    
    	 while(1){
     int ret = WSARecv(s1, &wbuf,1 , &dwBytesRet, &dwFlags, NULL, NULL);
    // recv(s1, buffer, sizeof(buffer), NULL);
      if (ret == SOCKET_ERROR){
    	  cout<<"WSARecv ERROR: "<<WSAGetLastError() << endl;
          WSACleanup();
    	  closesocket(s1);
    	  return -7;
      }else{ 
    	  cout<<"\n                 #######Packet Length: "<<wbuf.len<<endl;
    	  cout<<"                 #######Packet data#######\n";
    	  
    	  for(int ai = 0; ai < dwBytesRet; ai++){
    	  
    		  cout<<(int)wbuf.buf[ai]<<" ";  //I've tried litraly everything here, all data types I know have ended up casting it....
        
            
    	  }
    
    	  
    
      
      
      
      }
    	 }
    	
     cout<<"\n\n#########DATA TRAFIC ANILIZING COMPONENT#########\n\n#########END#########\n\n";
     return 0;
     
     }
    Please anyone, help me out, I've been stuck here for days now and I don't like being stuck

  2. #2
    radnomguywfq3's Avatar
    Join Date
    Jan 2007
    Gender
    male
    Location
    J:\E\T\A\M\A\Y.exe
    Posts
    8,858
    Reputation
    381
    Thanks
    1,823
    My Mood
    Sad
    You can use sprintf, which will write the byte to an allocated buffer in the desired format. Read here : sprintf - C++ Reference Note, some ascii keys have no character representation, and pasting the dump in ascii form on a thread will likely cause damage to the data as the forum posting system usually filters these obscure characters out.

    If your logging some sort of secure application, It is very likely this data goes under some sort of encryption process, and thus I would recommend you open your target in a disassembler and follow the execution back from the send routine. You need to find the source of the data buffer, so a breakpoint on read\write would be worth a go. Ofc it's always safer to do offline analysis, so if you can get your target unpacked then you're good to go.

    After you get the decrypted form of the data, you need to perform what is called "data reverse engineering". Which is the process of figuring out what the data fields inside the send dump mean. I.e, the first word may be a signature, the second may be a array of characters describing the player's name. This will likely require tracing the buffer back to it's source and determining where all the fields are set.

    Good luck.



    There are two types of tragedies in life. One is not getting what you want, the other is getting it.

    If you wake up at a different time in a different place, could you wake up as a different person?


  3. The Following 3 Users Say Thank You to radnomguywfq3 For This Useful Post:

    Hell_Demon (08-21-2010),schim (08-21-2010),Void (08-21-2010)

  4. #3
    Hell_Demon's Avatar
    Join Date
    Mar 2008
    Gender
    male
    Location
    I love causing havoc
    Posts
    3,976
    Reputation
    343
    Thanks
    4,320
    My Mood
    Cheeky
    cout<<hex<<(int)wbuf.buf[ai]; ?
    Ah we-a blaze the fyah, make it bun dem!

  5. #4
    schim's Avatar
    Join Date
    May 2010
    Gender
    male
    Location
    My chair
    Posts
    367
    Reputation
    10
    Thanks
    114
    My Mood
    Twisted
    Quote Originally Posted by Jetamay View Post
    You can use sprintf, which will write the byte to an allocated buffer in the desired format. Read here : sprintf - C++ Reference Note, some ascii keys have no character representation, and pasting the dump in ascii form on a thread will likely cause damage to the data as the forum posting system usually filters these obscure characters out.

    If your logging some sort of secure application, It is very likely this data goes under some sort of encryption process, and thus I would recommend you open your target in a disassembler and follow the execution back from the send routine. You need to find the source of the data buffer, so a breakpoint on read\write would be worth a go. Ofc it's always safer to do offline analysis, so if you can get your target unpacked then you're good to go.

    After you get the decrypted form of the data, you need to perform what is called "data reverse engineering". Which is the process of figuring out what the data fields inside the send dump mean. I.e, the first word may be a signature, the second may be a array of characters describing the player's name. This will likely require tracing the buffer back to it's source and determining where all the fields are set.

    Good luck.
    It's not encypted or anything because I'm logging all packets on my system so maybe this packet is encrypted, but all the packets I'm receiving are like this....

    But I'll look into sprintf

    cout<<hex<<(int)wbuf.buf[ai]; ?
    I've tried this, it works, but I still have a weir mixture of bytes and... er non bytes

    Code:
    40 0 5 ffffffffdc 77 fffffffc 40 0 3c 6 7f ffffff9a 52 5e ffffffe4 ffffff90 a 0 0
    As you can see, bytes and hex are kide mushed together

    But well I ques this is step forward...
    Last edited by schim; 08-21-2010 at 09:49 PM.

Similar Threads

  1. [Help]Problem with Player Stats?
    By mastermods in forum Combat Arms Hack Coding / Programming / Source Code
    Replies: 7
    Last Post: 08-26-2010, 05:26 AM
  2. [Help]Problem with Drawing + Value
    By HazXoD3D in forum Visual Basic Programming
    Replies: 0
    Last Post: 03-20-2010, 06:47 PM
  3. [Help] Problem with injecting hacks.
    By jjesper in forum Call of Duty Modern Warfare 2 Help
    Replies: 1
    Last Post: 03-06-2010, 03:30 PM
  4. HELP problems with all downloads
    By jaylord in forum Combat Arms Help
    Replies: 11
    Last Post: 09-15-2009, 05:34 PM
  5. help.. problem with hacking wolf team
    By x-storm in forum WolfTeam General
    Replies: 17
    Last Post: 07-05-2008, 06:34 AM