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{nYl@Ʉ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^88X7j_m{l <,XuyA`}otbseS*~}V#\>mn?!hoN*$h
sȴPb1ccm}0Ftp=Vf-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&?,`*sK*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