Salut a tous !

Je suis entrain de développer un petit tools pour envoyé un paquet SYN a un hote distant.

Le probléme est que le paquet ne pars pas .
Je n'ai aucun retour d'erreur, le programme se comporte comme si tous fonctionner, mais lorsque je sniff avec wireshark je ne vois aucune trace de mes paquets.

J'aimerais donc un peu d'aide pour trouver d'où viens l'erreur.

J'espère avoir bien expliqué mon problème, sinon dite le moi...

Voilà le code source:

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
 
#include <stdio.h>
#include <stdlib.h>
#include <windows.h>
#include <winsock2.h>
#include <ws2tcpip.h>
#include <time.h>
 
typedef struct ipHeader
{
 
    unsigned char ip_header_length:4;
    unsigned char version:4;
 
    unsigned char type_of_service;
    unsigned short int total_length;
    unsigned short int id;
    unsigned short int fragment_offset;
    unsigned char ttl;
    unsigned char protocol;
    unsigned short int checksum;
 
    unsigned int source_addr;
    unsigned int destination_addr;
 
}ipHeader;
 
 
typedef struct tcpHeader
{
 
    unsigned short int source_port;
    unsigned short int destination_port;
 
    unsigned int seq_num;
    unsigned int ack_num;
 
    unsigned char reserved1:4;
    unsigned char data_offset:4;
    unsigned short fin:1;
    unsigned short syn:1;
    unsigned short reset:1;
    unsigned short push:1;
    unsigned short ack:1;
    unsigned short urgent:1;
    unsigned short reserverd2:2;
 
    unsigned short int windows;
    unsigned short int checksum;
    unsigned short int urgent_ptr;
 
}tcpHeader;
 
 
unsigned short csum( unsigned short *buf , int len )
{
        unsigned long sum;
 
        for( sum = 0 ; len > 0 ; len-- )
                sum += *buf++;
        sum = ( sum >> 16 ) + ( sum &0xffff );
        sum += ( sum >> 16 );
        return ( unsigned short )( ~sum );
}
 
 
static void purger( void )
{
    int c;
 
    while( ( c = getchar() ) != '\n' && c != EOF )
    {
    }
}
 
static void clean( char *string )
{
    char *p = strchr( string , '\n' );
 
    if( p )
    {
        *p = 0;
    }
    else
    {
        purger();
    }
}
 
int main()
{
 
    WSADATA	wsaData;
 
    SOCKET sock;
 
    struct sockaddr_in target;
 
    int res;
    int one = 1;
    const int *val = &one;
 
    char src_ip[14];
    char dst_ip[14];
    char buff[1024];
 
    ipHeader *ipH = ( struct ipHeader *) buff;
    tcpHeader *tcpH = ( struct tcpHeader *)( buff + sizeof( ipHeader ) );
 
    srand( time( NULL ) );
 
    printf("[?]Source IP: ");
    fgets( src_ip , sizeof( src_ip ) , stdin );
    clean( src_ip );
 
    printf("\n[?]Target IP: ");
    fgets( dst_ip , sizeof( dst_ip ) , stdin );
    clean( dst_ip );
 
 
    target.sin_family = AF_INET;
    target.sin_port = htons( 80 );
    target.sin_addr.s_addr = inet_addr( dst_ip );
 
    res = WSAStartup( MAKEWORD( 2 , 0 ) , &wsaData);
 
    if( res != 0 )
    {
        printf("\n[-]Error Winsock version : %d\n" , WSAGetLastError() );
        system("PAUSE");
        return 0;
    }
 
    sock = socket( AF_INET , SOCK_RAW , IPPROTO_RAW );
 
    if( sock < 0 )
    {
        printf("\n[-]Error socket function : %d\n" , WSAGetLastError() );
        system("PAUSE");
        return 0;
    }
    else if( sock == INVALID_SOCKET )
    {
        printf("\n[-]Error socket function : %d\n" , WSAGetLastError() );
        system("PAUSE");
        return 0;
    }
 
    memset( buff , 0 , 1024 );
 
    ipH->version = 4;
    ipH->ip_header_length = 16;
    ipH->type_of_service = 0;
    ipH->total_length = htons( sizeof( struct ipHeader ) + sizeof( struct tcpHeader ) );
    ipH->id = 2;
    ipH->fragment_offset = 0;
    ipH->ttl = 128;
    ipH->protocol = 0x06;
    ipH->checksum = 0;
    ipH->source_addr = inet_addr( src_ip );
    ipH->destination_addr = inet_addr( dst_ip );
 
    tcpH->source_port = htons( 80 );
    tcpH->destination_port = htons( 80 );
    tcpH->seq_num = rand();
    tcpH->data_offset = 0;
    tcpH->ack_num = 0;
    tcpH->reserved1 = 0;
    tcpH->fin = 0;
    tcpH->syn = 1;
    tcpH->reset = 0;
    tcpH->push = 0;
    tcpH->ack = 0;
    tcpH->urgent = 0;
    tcpH->reserverd2 = 0;
    tcpH->windows = htonl (65535);
    tcpH->checksum = 0;
    tcpH->urgent_ptr = 0;
 
    ipH->checksum = csum( ( unsigned short * ) buff , ipH->total_length >> 1 );
 
    res = setsockopt( sock , IPPROTO_IP , IP_HDRINCL , val , sizeof( one ) );
 
    if( res == SOCKET_ERROR )
    {
 
        closesocket( sock );
 
        printf("\n[-]Error setsockop function");
    }
 
    if( sendto( sock , buff , ipH->total_length , 0 , ( struct sockaddr *) &target , sizeof( target ) ) < 0 )
    {
        printf("\n[-]Error socket function : %d\n" , WSAGetLastError() );
        system("PAUSE");
        return 0;
    }
    else
    {
        printf("\n[+]Packet send");
    }
 
 
 
    printf("\n");
    system("PAUSE");
    return 0;
}
Merci d'avance pour vos réponses