id
int64
4
16.3M
file_name
stringlengths
3
68
file_path
stringlengths
14
181
content
stringlengths
39
9.06M
size
int64
39
9.06M
language
stringclasses
1 value
extension
stringclasses
2 values
total_lines
int64
1
711k
avg_line_length
float64
3.18
138
max_line_length
int64
10
140
alphanum_fraction
float64
0.02
0.93
repo_name
stringlengths
7
69
repo_stars
int64
2
61.6k
repo_forks
int64
12
7.81k
repo_open_issues
int64
0
1.13k
repo_license
stringclasses
10 values
repo_extraction_date
stringclasses
657 values
exact_duplicates_stackv2
bool
1 class
exact_duplicates_stackv1
bool
1 class
exact_duplicates_redpajama
bool
1 class
exact_duplicates_githubcode
bool
2 classes
near_duplicates_stackv2
bool
1 class
near_duplicates_stackv1
bool
1 class
near_duplicates_redpajama
bool
1 class
near_duplicates_githubcode
bool
2 classes
4,974
br_fat32kos_0x52.h
pbatard_rufus/src/ms-sys/inc/br_fat32kos_0x52.h
unsigned char br_fat32kos_0x52[] = { 0x46, 0x41, 0x54, 0x33, 0x32, 0x20, 0x20, 0x20, 0x80, 0x3C, 0x80, 0x75, 0x09, 0x66, 0x8B, 0x44, 0x08, 0x2E, 0x66, 0xA3, 0x1C, 0x7C, 0x66, 0x31, 0xC0, 0x8E, 0xD8, 0x8E, 0xD0, 0xBC, 0x00, 0x7C, 0x89, 0xE5, 0x88, 0x16, 0x08, 0x7A, 0xFC, 0xFB, 0x68, 0x00, 0x08, 0x07, 0x66, 0x0F, 0xB7, 0x5E, 0x0E, 0x66, 0x89, 0x1E, 0x00, 0x7A, 0x8A, 0x46, 0x10, 0x66, 0xF7, 0x66, 0x24, 0x66, 0x01, 0xD8, 0x66, 0x0F, 0xB6, 0x5E, 0x0D, 0x01, 0xDB, 0x66, 0x29, 0xD8, 0x66, 0xA3, 0x04, 0x7A, 0x66, 0x8B, 0x46, 0x2C, 0x66, 0x25, 0xFF, 0xFF, 0xFF, 0x0F, 0x31, 0xDB, 0x89, 0xDF, 0x66, 0x50, 0xE8, 0x62, 0x00, 0x0F, 0xB6, 0x4E, 0x0D, 0xC1, 0xE1, 0x04, 0x26, 0x80, 0x3D, 0x00, 0x74, 0x4D, 0x51, 0x57, 0xB9, 0x0B, 0x00, 0xBE, 0xCB, 0x7D, 0xF3, 0xA6, 0x5F, 0x59, 0x74, 0x0E, 0x83, 0xC7, 0x20, 0xE2, 0xE7, 0x66, 0x58, 0xE8, 0x8D, 0x00, 0x73, 0x33, 0x72, 0xCE, 0x66, 0x58, 0x26, 0x8B, 0x45, 0x14, 0x25, 0xFF, 0x0F, 0x66, 0xC1, 0xE0, 0x10, 0x26, 0x8B, 0x45, 0x1A, 0x31, 0xDB, 0x66, 0x50, 0xE8, 0x21, 0x00, 0x8C, 0xC0, 0x0F, 0xB6, 0x4E, 0x0D, 0xC1, 0xE1, 0x05, 0x01, 0xC8, 0x8E, 0xC0, 0x66, 0x58, 0xE8, 0x5F, 0x00, 0x72, 0xE5, 0xEA, 0x00, 0x80, 0x00, 0x00, 0xBE, 0xBA, 0x7D, 0xE8, 0x98, 0x00, 0xEB, 0xFE, 0x66, 0x0F, 0xB6, 0x4E, 0x0D, 0x66, 0xF7, 0xE1, 0x66, 0x03, 0x06, 0x04, 0x7A, 0x66, 0x03, 0x46, 0x1C, 0x06, 0x66, 0x60, 0x6A, 0x00, 0x6A, 0x00, 0x66, 0x50, 0x06, 0x53, 0x83, 0xE9, 0x7F, 0x19, 0xC0, 0x21, 0xC8, 0x83, 0xC0, 0x7F, 0x50, 0xC1, 0xE0, 0x05, 0x8C, 0xC1, 0x01, 0xC1, 0x8E, 0xC1, 0x6A, 0x10, 0xB8, 0x00, 0x42, 0x8A, 0x16, 0x08, 0x7A, 0x89, 0xE6, 0xCD, 0x13, 0xBE, 0xD9, 0x7D, 0x72, 0xB9, 0x61, 0x66, 0x61, 0x66, 0x83, 0xC0, 0x7F, 0x83, 0xE9, 0x7F, 0x77, 0xC4, 0x07, 0xC3, 0x06, 0x1E, 0x07, 0xBB, 0x00, 0x7E, 0x66, 0x50, 0x66, 0xC1, 0xE8, 0x07, 0x66, 0x3B, 0x06, 0xF9, 0x7D, 0x74, 0x0F, 0x66, 0xA3, 0xF9, 0x7D, 0x66, 0x03, 0x06, 0x00, 0x7A, 0xB9, 0x01, 0x00, 0xE8, 0x9B, 0xFF, 0x66, 0x58, 0x66, 0x83, 0xE0, 0x7F, 0x67, 0x66, 0x8B, 0x04, 0x85, 0x00, 0x7E, 0x00, 0x00, 0x66, 0x25, 0xFF, 0xFF, 0xFF, 0x0F, 0x66, 0x3D, 0xF7, 0xFF, 0xFF, 0x0F, 0xBE, 0xEB, 0x7D, 0x0F, 0x84, 0x67, 0xFF, 0x07, 0xC3, 0xAC, 0x84, 0xC0, 0x74, 0x09, 0xB4, 0x0E, 0xBB, 0x07, 0x00, 0xCD, 0x10, 0xEB, 0xF2, 0xC3, 0x43, 0x61, 0x6E, 0x6E, 0x6F, 0x74, 0x20, 0x66, 0x69, 0x6E, 0x64, 0x20, 0x66, 0x69, 0x6C, 0x65, 0x20, 0x4D, 0x54, 0x4C, 0x44, 0x5F, 0x46, 0x33, 0x32, 0x20, 0x20, 0x20, 0x0D, 0x0A, 0x00, 0x44, 0x69, 0x73, 0x6B, 0x20, 0x72, 0x65, 0x61, 0x64, 0x20, 0x65, 0x72, 0x72, 0x6F, 0x72, 0x0D, 0x0A, 0x00, 0x42, 0x61, 0x64, 0x20, 0x63, 0x6C, 0x75, 0x73, 0x74, 0x65, 0x72, 0x0D, 0x0A, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x55, 0xAA };
2,655
C
.h
38
67.921053
72
0.667176
pbatard/rufus
28,236
2,528
13
GPL-3.0
9/7/2024, 9:40:14 AM (Europe/Amsterdam)
false
false
false
true
false
false
false
true
4,975
br_fat32fd_0x3f0.h
pbatard_rufus/src/ms-sys/inc/br_fat32fd_0x3f0.h
/* br_fat32_0x52.h // // ANI // substring gmbh/tw 14.9.04 // modified cluster code 0x3f0 to support FreeDOS */ unsigned char br_fat32_0x3f0[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x55, 0xaa, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x55, 0xaa };
3,537
C
.h
52
62.769231
76
0.634615
pbatard/rufus
28,236
2,528
13
GPL-3.0
9/7/2024, 9:40:14 AM (Europe/Amsterdam)
false
false
false
true
false
false
false
true
4,976
br_fat32_0x3f0.h
pbatard_rufus/src/ms-sys/inc/br_fat32_0x3f0.h
unsigned char br_fat32_0x3f0[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x55, 0xaa, 0xfa, 0x66, 0x0f, 0xb6, 0x46, 0x10, 0x66, 0x8b, 0x4e, 0x24, 0x66, 0xf7, 0xe1, 0x66, 0x03, 0x46, 0x1c, 0x66, 0x0f, 0xb7, 0x56, 0x0e, 0x66, 0x03, 0xc2, 0x33, 0xc9, 0x66, 0x89, 0x46, 0xfc, 0x66, 0xc7, 0x46, 0xf8, 0xff, 0xff, 0xff, 0xff, 0xfa, 0x66, 0x8b, 0x46, 0x2c, 0x66, 0x83, 0xf8, 0x02, 0x0f, 0x82, 0xcf, 0xfc, 0x66, 0x3d, 0xf8, 0xff, 0xff, 0x0f, 0x0f, 0x83, 0xc5, 0xfc, 0x66, 0x0f, 0xa4, 0xc2, 0x10, 0xfb, 0x52, 0x50, 0xfa, 0x66, 0xc1, 0xe0, 0x10, 0x66, 0x0f, 0xac, 0xd0, 0x10, 0x66, 0x83, 0xe8, 0x02, 0x66, 0x0f, 0xb6, 0x5e, 0x0d, 0x8b, 0xf3, 0x66, 0xf7, 0xe3, 0x66, 0x03, 0x46, 0xfc, 0x66, 0x0f, 0xa4, 0xc2, 0x10, 0xfb, 0xbb, 0x00, 0x07, 0x8b, 0xfb, 0xb9, 0x01, 0x00, 0xe8, 0xbe, 0xfc, 0x0f, 0x82, 0xaa, 0xfc, 0x38, 0x2d, 0x74, 0x1e, 0xb1, 0x0b, 0x56, 0xbe, 0xd8, 0x7d, 0xf3, 0xa6, 0x5e, 0x74, 0x19, 0x03, 0xf9, 0x83, 0xc7, 0x15, 0x3b, 0xfb, 0x72, 0xe8, 0x4e, 0x75, 0xd6, 0x58, 0x5a, 0xe8, 0x66, 0x00, 0x72, 0xab, 0x83, 0xc4, 0x04, 0xe9, 0x64, 0xfc, 0x83, 0xc4, 0x04, 0x8b, 0x75, 0x09, 0x8b, 0x7d, 0x0f, 0x8b, 0xc6, 0xfa, 0x66, 0xc1, 0xe0, 0x10, 0x8b, 0xc7, 0x66, 0x83, 0xf8, 0x02, 0x72, 0x3b, 0x66, 0x3d, 0xf8, 0xff, 0xff, 0x0f, 0x73, 0x33, 0x66, 0x48, 0x66, 0x48, 0x66, 0x0f, 0xb6, 0x4e, 0x0d, 0x66, 0xf7, 0xe1, 0x66, 0x03, 0x46, 0xfc, 0x66, 0x0f, 0xa4, 0xc2, 0x10, 0xfb, 0xbb, 0x00, 0x07, 0x53, 0xb9, 0x04, 0x00, 0xe8, 0x52, 0xfc, 0x5b, 0x0f, 0x82, 0x3d, 0xfc, 0x81, 0x3f, 0x4d, 0x5a, 0x75, 0x08, 0x81, 0xbf, 0x00, 0x02, 0x42, 0x4a, 0x74, 0x06, 0xbe, 0x80, 0x7d, 0xe9, 0x0e, 0xfc, 0xea, 0x00, 0x02, 0x70, 0x00, 0x03, 0xc0, 0x13, 0xd2, 0x03, 0xc0, 0x13, 0xd2, 0xe8, 0x18, 0x00, 0xfa, 0x26, 0x66, 0x8b, 0x01, 0x66, 0x25, 0xff, 0xff, 0xff, 0x0f, 0x66, 0x0f, 0xa4, 0xc2, 0x10, 0x66, 0x3d, 0xf8, 0xff, 0xff, 0x0f, 0xfb, 0xc3, 0xbf, 0x00, 0x7e, 0xfa, 0x66, 0xc1, 0xe0, 0x10, 0x66, 0x0f, 0xac, 0xd0, 0x10, 0x66, 0x0f, 0xb7, 0x4e, 0x0b, 0x66, 0x33, 0xd2, 0x66, 0xf7, 0xf1, 0x66, 0x3b, 0x46, 0xf8, 0x74, 0x44, 0x66, 0x89, 0x46, 0xf8, 0x66, 0x03, 0x46, 0x1c, 0x66, 0x0f, 0xb7, 0x4e, 0x0e, 0x66, 0x03, 0xc1, 0x66, 0x0f, 0xb7, 0x5e, 0x28, 0x83, 0xe3, 0x0f, 0x74, 0x16, 0x3a, 0x5e, 0x10, 0x0f, 0x83, 0xa4, 0xfb, 0x52, 0x66, 0x8b, 0xc8, 0x66, 0x8b, 0x46, 0x24, 0x66, 0xf7, 0xe3, 0x66, 0x03, 0xc1, 0x5a, 0x52, 0x66, 0x0f, 0xa4, 0xc2, 0x10, 0xfb, 0x8b, 0xdf, 0xb9, 0x01, 0x00, 0xe8, 0xb4, 0xfb, 0x5a, 0x0f, 0x82, 0x9f, 0xfb, 0xfb, 0x8b, 0xda, 0xc3, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x55, 0xaa };
3,293
C
.h
46
68.673913
73
0.657838
pbatard/rufus
28,236
2,528
13
GPL-3.0
9/7/2024, 9:40:14 AM (Europe/Amsterdam)
false
false
false
true
false
false
false
true
4,977
partition_info.h
pbatard_rufus/src/ms-sys/inc/partition_info.h
#ifndef PARTITION_INFO_H #define PARTITION_INFO_H /* Writes the number of heads to a partition returns TRUE on success, otherwise FALSE */ int write_partition_number_of_heads(FILE *fp, int iHeads); /* Writes the start sector number to a partition (also known as "number of hidden sectors"), returns TRUE on success, otherwise FALSE */ int write_partition_start_sector_number(FILE *fp, int iStartSector); /* Writes a physical disk drive id of 0x80 (for C:) to a partition */ int write_partition_physical_disk_drive_id_fat32(FILE *fp); int write_partition_physical_disk_drive_id_fat16(FILE *fp); #endif
611
C
.h
12
49.083333
75
0.771429
pbatard/rufus
28,236
2,528
13
GPL-3.0
9/7/2024, 9:40:14 AM (Europe/Amsterdam)
false
false
false
true
false
false
false
true
4,978
mbr_vista.h
pbatard_rufus/src/ms-sys/inc/mbr_vista.h
/* First 446 bytes of MBR from Windows Vista */ /* This is English version. Bytes 0x162 onwards vary with language. */ /* Last three bytes 1b5-1b7 point to language-specific messages. */ /* Support of other languages is an exercise for the reader! */ /* see: http://thestarman.pcministry.com/asm/mbr/VistaMBR.htm */ #define MBR_VISTA_LANG_INDEP_LEN 0x162 unsigned char mbr_vista_0x0[] = { 0x33, 0xc0, 0x8e, 0xd0, 0xbc, 0x00, 0x7c, 0x8e, 0xc0, 0x8e, 0xd8, 0xbe, 0x00, 0x7c, 0xbf, 0x00, 0x06, 0xb9, 0x00, 0x02, 0xfc, 0xf3, 0xa4, 0x50, 0x68, 0x1c, 0x06, 0xcb, 0xfb, 0xb9, 0x04, 0x00, 0xbd, 0xbe, 0x07, 0x80, 0x7e, 0x00, 0x00, 0x7c, 0x0b, 0x0f, 0x85, 0x10, 0x01, 0x83, 0xc5, 0x10, 0xe2, 0xf1, 0xcd, 0x18, 0x88, 0x56, 0x00, 0x55, 0xc6, 0x46, 0x11, 0x05, 0xc6, 0x46, 0x10, 0x00, 0xb4, 0x41, 0xbb, 0xaa, 0x55, 0xcd, 0x13, 0x5d, 0x72, 0x0f, 0x81, 0xfb, 0x55, 0xaa, 0x75, 0x09, 0xf7, 0xc1, 0x01, 0x00, 0x74, 0x03, 0xfe, 0x46, 0x10, 0x66, 0x60, 0x80, 0x7e, 0x10, 0x00, 0x74, 0x26, 0x66, 0x68, 0x00, 0x00, 0x00, 0x00, 0x66, 0xff, 0x76, 0x08, 0x68, 0x00, 0x00, 0x68, 0x00, 0x7c, 0x68, 0x01, 0x00, 0x68, 0x10, 0x00, 0xb4, 0x42, 0x8a, 0x56, 0x00, 0x8b, 0xf4, 0xcd, 0x13, 0x9f, 0x83, 0xc4, 0x10, 0x9e, 0xeb, 0x14, 0xb8, 0x01, 0x02, 0xbb, 0x00, 0x7c, 0x8a, 0x56, 0x00, 0x8a, 0x76, 0x01, 0x8a, 0x4e, 0x02, 0x8a, 0x6e, 0x03, 0xcd, 0x13, 0x66, 0x61, 0x73, 0x1e, 0xfe, 0x4e, 0x11, 0x0f, 0x85, 0x0c, 0x00, 0x80, 0x7e, 0x00, 0x80, 0x0f, 0x84, 0x8a, 0x00, 0xb2, 0x80, 0xeb, 0x82, 0x55, 0x32, 0xe4, 0x8a, 0x56, 0x00, 0xcd, 0x13, 0x5d, 0xeb, 0x9c, 0x81, 0x3e, 0xfe, 0x7d, 0x55, 0xaa, 0x75, 0x6e, 0xff, 0x76, 0x00, 0xe8, 0x8a, 0x00, 0x0f, 0x85, 0x15, 0x00, 0xb0, 0xd1, 0xe6, 0x64, 0xe8, 0x7f, 0x00, 0xb0, 0xdf, 0xe6, 0x60, 0xe8, 0x78, 0x00, 0xb0, 0xff, 0xe6, 0x64, 0xe8, 0x71, 0x00, 0xb8, 0x00, 0xbb, 0xcd, 0x1a, 0x66, 0x23, 0xc0, 0x75, 0x3b, 0x66, 0x81, 0xfb, 0x54, 0x43, 0x50, 0x41, 0x75, 0x32, 0x81, 0xf9, 0x02, 0x01, 0x72, 0x2c, 0x66, 0x68, 0x07, 0xbb, 0x00, 0x00, 0x66, 0x68, 0x00, 0x02, 0x00, 0x00, 0x66, 0x68, 0x08, 0x00, 0x00, 0x00, 0x66, 0x53, 0x66, 0x53, 0x66, 0x55, 0x66, 0x68, 0x00, 0x00, 0x00, 0x00, 0x66, 0x68, 0x00, 0x7c, 0x00, 0x00, 0x66, 0x61, 0x68, 0x00, 0x00, 0x07, 0xcd, 0x1a, 0x5a, 0x32, 0xf6, 0xea, 0x00, 0x7c, 0x00, 0x00, 0xcd, 0x18, 0xa0, 0xb7, 0x07, 0xeb, 0x08, 0xa0, 0xb6, 0x07, 0xeb, 0x03, 0xa0, 0xb5, 0x07, 0x32, 0xe4, 0x05, 0x00, 0x07, 0x8b, 0xf0, 0xac, 0x3c, 0x00, 0x74, 0xfc, 0xbb, 0x07, 0x00, 0xb4, 0x0e, 0xcd, 0x10, 0xeb, 0xf2, 0x2b, 0xc9, 0xe4, 0x64, 0xeb, 0x00, 0x24, 0x02, 0xe0, 0xf8, 0x24, 0x02, 0xc3, 0x49, 0x6e, 0x76, 0x61, 0x6c, 0x69, 0x64, 0x20, 0x70, 0x61, 0x72, 0x74, 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x74, 0x61, 0x62, 0x6c, 0x65, 0x00, 0x45, 0x72, 0x72, 0x6f, 0x72, 0x20, 0x6c, 0x6f, 0x61, 0x64, 0x69, 0x6e, 0x67, 0x20, 0x6f, 0x70, 0x65, 0x72, 0x61, 0x74, 0x69, 0x6e, 0x67, 0x20, 0x73, 0x79, 0x73, 0x74, 0x65, 0x6d, 0x00, 0x4d, 0x69, 0x73, 0x73, 0x69, 0x6e, 0x67, 0x20, 0x6f, 0x70, 0x65, 0x72, 0x61, 0x74, 0x69, 0x6e, 0x67, 0x20, 0x73, 0x79, 0x73, 0x74, 0x65, 0x6d, 0x00, 0x00, 0x00, 0x00, 0x62, 0x7a, 0x99 }; /* Next four bytes used for Windows Disk Signature / Drive serial number */ /* unsigned char mbr_vista_0x1b8[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; */
3,255
C
.h
52
60.596154
75
0.67187
pbatard/rufus
28,236
2,528
13
GPL-3.0
9/7/2024, 9:40:14 AM (Europe/Amsterdam)
false
false
false
true
false
false
false
true
4,980
fat16.h
pbatard_rufus/src/ms-sys/inc/fat16.h
#ifndef FAT16_H #define FAT16_H #include <stdio.h> /* returns TRUE if the file has a FAT16 file system, otherwise FALSE. The file position will change when this function is called! */ int is_fat_16_fs(FILE *fp); /* returns TRUE if the file has a FAT16 boot record, otherwise FALSE. The file position will change when this function is called! */ int is_fat_16_br(FILE *fp); /* returns TRUE if the file has an exact match of the FAT16 boot record this program would create, otherwise FALSE. The file position will change when this function is called! */ int entire_fat_16_br_matches(FILE *fp); /* Writes a FAT16 boot record to a file, returns TRUE on success, otherwise FALSE */ int write_fat_16_br(FILE *fp, int bKeepLabel); /* returns TRUE if the file has an exact match of the FAT16 boot record this program would create for FreeDOS, otherwise FALSE. The file position will change when this function is called! */ int entire_fat_16_fd_br_matches(FILE *fp); /* Writes a FAT16 FreeDOS boot record to a file, returns TRUE on success, otherwise FALSE */ int write_fat_16_fd_br(FILE *fp, int bKeepLabel); /* returns TRUE if the file has an exact match of the FAT16 boot record this program would create for ReactOS, otherwise FALSE. The file position will change when this function is called! */ int entire_fat_16_ros_br_matches(FILE *fp); /* Writes a FAT16 ReactOS boot record to a file, returns TRUE on success, otherwise FALSE */ int write_fat_16_ros_br(FILE *fp, int bKeepLabel); #endif
1,530
C
.h
31
46.967742
76
0.754869
pbatard/rufus
28,236
2,528
13
GPL-3.0
9/7/2024, 9:40:14 AM (Europe/Amsterdam)
false
false
false
true
false
false
false
true
4,982
mbr_gpt_syslinux.h
pbatard_rufus/src/ms-sys/inc/mbr_gpt_syslinux.h
/* This version is from gptmbr.bin from syslinux 6.02 */ unsigned char mbr_gpt_syslinux_0x0[] = { 0x33, 0xc0, 0xfa, 0x8e, 0xd8, 0x8e, 0xd0, 0xbc, 0x00, 0x7c, 0x89, 0xe6, 0x06, 0x57, 0x8e, 0xc0, 0xfb, 0xfc, 0xbf, 0x00, 0x06, 0xb9, 0x00, 0x01, 0xf3, 0xa5, 0xea, 0x1f, 0x06, 0x00, 0x00, 0x52, 0x89, 0xe5, 0x83, 0xec, 0x1c, 0x6a, 0x1e, 0xc7, 0x46, 0xfa, 0x00, 0x02, 0x52, 0xb4, 0x41, 0xbb, 0xaa, 0x55, 0x31, 0xc9, 0x30, 0xf6, 0xf9, 0xcd, 0x13, 0x5a, 0xb4, 0x08, 0x72, 0x17, 0x81, 0xfb, 0x55, 0xaa, 0x75, 0x11, 0xd1, 0xe9, 0x73, 0x0d, 0x66, 0xc7, 0x06, 0x59, 0x07, 0xb4, 0x42, 0xeb, 0x13, 0xb4, 0x48, 0x89, 0xe6, 0xcd, 0x13, 0x83, 0xe1, 0x3f, 0x51, 0x0f, 0xb6, 0xc6, 0x40, 0xf7, 0xe1, 0x52, 0x50, 0x66, 0x31, 0xc0, 0x66, 0x99, 0x40, 0xe8, 0xdc, 0x00, 0x8b, 0x4e, 0x56, 0x8b, 0x46, 0x5a, 0x50, 0x51, 0xf7, 0xe1, 0xf7, 0x76, 0xfa, 0x91, 0x41, 0x66, 0x8b, 0x46, 0x4e, 0x66, 0x8b, 0x56, 0x52, 0x53, 0xe8, 0xc4, 0x00, 0xe2, 0xfb, 0x31, 0xf6, 0x5f, 0x59, 0x58, 0x66, 0x8b, 0x15, 0x66, 0x0b, 0x55, 0x04, 0x66, 0x0b, 0x55, 0x08, 0x66, 0x0b, 0x55, 0x0c, 0x74, 0x0c, 0xf6, 0x45, 0x30, 0x04, 0x74, 0x06, 0x21, 0xf6, 0x75, 0x19, 0x89, 0xfe, 0x01, 0xc7, 0xe2, 0xdf, 0x21, 0xf6, 0x75, 0x2e, 0xe8, 0xe1, 0x00, 0x4d, 0x69, 0x73, 0x73, 0x69, 0x6e, 0x67, 0x20, 0x4f, 0x53, 0x0d, 0x0a, 0xe8, 0xd2, 0x00, 0x4d, 0x75, 0x6c, 0x74, 0x69, 0x70, 0x6c, 0x65, 0x20, 0x61, 0x63, 0x74, 0x69, 0x76, 0x65, 0x20, 0x70, 0x61, 0x72, 0x74, 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x0d, 0x0a, 0x91, 0xbf, 0xbe, 0x07, 0x57, 0x66, 0x31, 0xc0, 0xb0, 0x80, 0x66, 0xab, 0xb0, 0xed, 0x66, 0xab, 0x66, 0x8b, 0x44, 0x20, 0x66, 0x8b, 0x54, 0x24, 0xe8, 0x40, 0x00, 0x66, 0x8b, 0x44, 0x28, 0x66, 0x8b, 0x54, 0x2c, 0x66, 0x2b, 0x44, 0x20, 0x66, 0x1b, 0x54, 0x24, 0xe8, 0x70, 0x00, 0xe8, 0x2a, 0x00, 0x66, 0x0f, 0xb7, 0xc1, 0x66, 0xab, 0xf3, 0xa4, 0x5e, 0x66, 0x8b, 0x44, 0x34, 0x66, 0x8b, 0x54, 0x38, 0xe8, 0x22, 0x00, 0x81, 0x3e, 0xfe, 0x7d, 0x55, 0xaa, 0x75, 0x85, 0x89, 0xec, 0x5a, 0x5f, 0x07, 0x66, 0xb8, 0x21, 0x47, 0x50, 0x54, 0xfa, 0xff, 0xe4, 0x66, 0x21, 0xd2, 0x74, 0x04, 0x66, 0x83, 0xc8, 0xff, 0x66, 0xab, 0xc3, 0xbb, 0x00, 0x7c, 0x66, 0x60, 0x66, 0x52, 0x66, 0x50, 0x06, 0x53, 0x6a, 0x01, 0x6a, 0x10, 0x89, 0xe6, 0x66, 0xf7, 0x76, 0xdc, 0xc0, 0xe4, 0x06, 0x88, 0xe1, 0x88, 0xc5, 0x92, 0xf6, 0x76, 0xe0, 0x88, 0xc6, 0x08, 0xe1, 0x41, 0xb8, 0x01, 0x02, 0x8a, 0x56, 0x00, 0xcd, 0x13, 0x8d, 0x64, 0x10, 0x66, 0x61, 0x72, 0x0c, 0x02, 0x7e, 0xfb, 0x66, 0x83, 0xc0, 0x01, 0x66, 0x83, 0xd2, 0x00, 0xc3, 0xe8, 0x0c, 0x00, 0x44, 0x69, 0x73, 0x6b, 0x20, 0x65, 0x72, 0x72, 0x6f, 0x72, 0x0d, 0x0a, 0x5e, 0xac, 0xb4, 0x0e, 0x8a, 0x3e, 0x62, 0x04, 0xb3, 0x07, 0xcd, 0x10, 0x3c, 0x0a, 0x75, 0xf1, 0xcd, 0x18, 0xf4, 0xeb, 0xfd, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
2,814
C
.h
40
67.5
73
0.659697
pbatard/rufus
28,236
2,528
13
GPL-3.0
9/7/2024, 9:40:14 AM (Europe/Amsterdam)
false
false
false
true
false
false
false
true
4,983
fat32.h
pbatard_rufus/src/ms-sys/inc/fat32.h
#ifndef FAT32_H #define FAT32_H #include <stdio.h> /* returns TRUE if the file has a FAT32 file system, otherwise FALSE. The file position will change when this function is called! */ int is_fat_32_fs(FILE *fp); /* returns TRUE if the file has a FAT32 DOS boot record, otherwise FALSE. The file position will change when this function is called! */ int is_fat_32_br(FILE *fp); /* returns TRUE if the file has an exact match of the FAT32 DOS boot record this program would create, otherwise FALSE. The file position will change when this function is called! */ int entire_fat_32_br_matches(FILE *fp); /* Writes a FAT32 DOS boot record to a file, returns TRUE on success, otherwise FALSE */ int write_fat_32_br(FILE *fp, int bKeepLabel); /* returns TRUE if the file has an exact match of the FAT32 boot record this program would create for FreeDOS, otherwise FALSE. The file position will change when this function is called! */ int entire_fat_32_fd_br_matches(FILE *fp); /* Writes a FAT32 FreeDOS boot record to a file, returns TRUE on success, otherwise FALSE */ int write_fat_32_fd_br(FILE *fp, int bKeepLabel); /* returns TRUE if the file has an exact match of the FAT32 boot record this program would create for NT, otherwise FALSE. The file position will change when this function is called! */ int entire_fat_32_nt_br_matches(FILE *fp); /* Writes a FAT32 NT boot record to a file, returns TRUE on success, otherwise FALSE */ int write_fat_32_nt_br(FILE *fp, int bKeepLabel); /* returns TRUE if the file has an exact match of the FAT32 boot record this program would create for NT, otherwise FALSE. The file position will change when this function is called! */ int entire_fat_32_pe_br_matches(FILE *fp); /* Writes a FAT32 NT boot record to a file, returns TRUE on success, otherwise FALSE */ int write_fat_32_pe_br(FILE *fp, int bKeepLabel); /* returns TRUE if the file has an exact match of the FAT32 boot record this program would create for ReactOS, otherwise FALSE. The file position will change when this function is called! */ int entire_fat_32_ros_br_matches(FILE *fp); /* Writes a FAT32 ReactOS boot record to a file, returns TRUE on success, otherwise FALSE */ int write_fat_32_ros_br(FILE *fp, int bKeepLabel); /* returns TRUE if the file has an exact match of the FAT32 boot record this program would create for KolibriOS, otherwise FALSE. The file position will change when this function is called! */ int entire_fat_32_kos_br_matches(FILE *fp); /* Writes a FAT32 KolibriOS boot record to a file, returns TRUE on success, otherwise FALSE */ int write_fat_32_kos_br(FILE *fp, int bKeepLabel); #endif
2,692
C
.h
52
49.307692
85
0.754573
pbatard/rufus
28,236
2,528
13
GPL-3.0
9/7/2024, 9:40:14 AM (Europe/Amsterdam)
false
false
false
true
false
false
false
true
4,984
br_fat32nt_0x1800.h
pbatard_rufus/src/ms-sys/inc/br_fat32nt_0x1800.h
unsigned char br_fat32nt_0x1800[] = { 0x66, 0x0f, 0xb6, 0x46, 0x10, 0x66, 0x8b, 0x4e, 0x24, 0x66, 0xf7, 0xe1, 0x66, 0x03, 0x46, 0x1c, 0x66, 0x0f, 0xb7, 0x56, 0x0e, 0x66, 0x03, 0xc2, 0x66, 0x89, 0x46, 0xfc, 0x66, 0xc7, 0x46, 0xf4, 0xff, 0xff, 0xff, 0xff, 0x66, 0x8b, 0x46, 0x2c, 0x66, 0x83, 0xf8, 0x02, 0x0f, 0x82, 0xa6, 0xfc, 0x66, 0x3d, 0xf8, 0xff, 0xff, 0x0f, 0x0f, 0x83, 0x9c, 0xfc, 0x66, 0x50, 0x66, 0x83, 0xe8, 0x02, 0x66, 0x0f, 0xb6, 0x5e, 0x0d, 0x8b, 0xf3, 0x66, 0xf7, 0xe3, 0x66, 0x03, 0x46, 0xfc, 0xbb, 0x00, 0x82, 0x8b, 0xfb, 0xb9, 0x01, 0x00, 0xe8, 0x87, 0xfc, 0x38, 0x2d, 0x74, 0x1e, 0xb1, 0x0b, 0x56, 0xbe, 0x70, 0x7d, 0xf3, 0xa6, 0x5e, 0x74, 0x1b, 0x03, 0xf9, 0x83, 0xc7, 0x15, 0x3b, 0xfb, 0x72, 0xe8, 0x4e, 0x75, 0xda, 0x66, 0x58, 0xe8, 0x65, 0x00, 0x72, 0xbf, 0x83, 0xc4, 0x04, 0xe9, 0x55, 0xfc, 0x00, 0x20, 0x83, 0xc4, 0x04, 0x8b, 0x75, 0x09, 0x8b, 0x7d, 0x0f, 0x8b, 0xc6, 0x66, 0xc1, 0xe0, 0x10, 0x8b, 0xc7, 0x66, 0x83, 0xf8, 0x02, 0x0f, 0x82, 0x3a, 0xfc, 0x66, 0x3d, 0xf8, 0xff, 0xff, 0x0f, 0x0f, 0x83, 0x30, 0xfc, 0x66, 0x50, 0x66, 0x83, 0xe8, 0x02, 0x66, 0x0f, 0xb6, 0x4e, 0x0d, 0x66, 0xf7, 0xe1, 0x66, 0x03, 0x46, 0xfc, 0xbb, 0x00, 0x00, 0x06, 0x8e, 0x06, 0x81, 0x80, 0xe8, 0x1d, 0xfc, 0x07, 0x66, 0x58, 0xc1, 0xeb, 0x04, 0x01, 0x1e, 0x81, 0x80, 0xe8, 0x0e, 0x00, 0x0f, 0x83, 0x02, 0x00, 0x72, 0xd0, 0x8a, 0x56, 0x40, 0xea, 0x00, 0x00, 0x00, 0x20, 0x66, 0xc1, 0xe0, 0x02, 0xe8, 0x11, 0x00, 0x26, 0x66, 0x8b, 0x01, 0x66, 0x25, 0xff, 0xff, 0xff, 0x0f, 0x66, 0x3d, 0xf8, 0xff, 0xff, 0x0f, 0xc3, 0xbf, 0x00, 0x7e, 0x66, 0x0f, 0xb7, 0x4e, 0x0b, 0x66, 0x33, 0xd2, 0x66, 0xf7, 0xf1, 0x66, 0x3b, 0x46, 0xf4, 0x74, 0x3a, 0x66, 0x89, 0x46, 0xf4, 0x66, 0x03, 0x46, 0x1c, 0x66, 0x0f, 0xb7, 0x4e, 0x0e, 0x66, 0x03, 0xc1, 0x66, 0x0f, 0xb7, 0x5e, 0x28, 0x83, 0xe3, 0x0f, 0x74, 0x16, 0x3a, 0x5e, 0x10, 0x0f, 0x83, 0xab, 0xfb, 0x52, 0x66, 0x8b, 0xc8, 0x66, 0x8b, 0x46, 0x24, 0x66, 0xf7, 0xe3, 0x66, 0x03, 0xc1, 0x5a, 0x52, 0x8b, 0xdf, 0xb9, 0x01, 0x00, 0xe8, 0x9d, 0xfb, 0x5a, 0x8b, 0xda, 0xc3, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x55, 0xaa };
3,198
C
.h
45
68.155556
73
0.658103
pbatard/rufus
28,236
2,528
13
GPL-3.0
9/7/2024, 9:40:14 AM (Europe/Amsterdam)
false
false
false
true
false
false
false
true
4,985
nls.h
pbatard_rufus/src/ms-sys/inc/nls.h
#ifndef NLS_H #define NLS_H #include <libintl.h> #ifdef NO_LIBINTL_OR_GETTEXT #define _(String) (String) #else #define _(String) gettext(String) #endif #define gettext_noop(String) (String) #define N_(String) gettext_noop(String) /* Init Native language support */ void nls_init(void); #endif
297
C
.h
13
21.538462
39
0.764286
pbatard/rufus
28,236
2,528
13
GPL-3.0
9/7/2024, 9:40:14 AM (Europe/Amsterdam)
false
false
false
true
false
false
false
true
4,986
fat12.h
pbatard_rufus/src/ms-sys/inc/fat12.h
#ifndef FAT12_H #define FAT12_H /* returns TRUE if the file has a FAT12 file system, otherwise FALSE. The file position will change when this function is called! */ int is_fat_12_fs(FILE *fp); /* returns TRUE if the file has an exact match ot the FAT12 boot record this program would create, otherwise FALSE. The file position will change when this function is called! */ int entire_fat_12_br_matches(FILE *fp); /* Writes a FAT12 boot record to a file, returns TRUE on success, otherwise FALSE */ int write_fat_12_br(FILE *fp, int bKeepLabel); #endif
568
C
.h
13
41.384615
76
0.754545
pbatard/rufus
28,236
2,528
13
GPL-3.0
9/7/2024, 9:40:14 AM (Europe/Amsterdam)
false
false
false
true
false
false
false
true
4,987
mbr_rufus.h
pbatard_rufus/src/ms-sys/inc/mbr_rufus.h
/* * First 440 bytes of Rufus MBR * https://github.com/pbatard/rufus/tree/master/res/mbr * Copyright © 2012-2014 Pete Batard <[email protected]> */ unsigned char mbr_rufus_0x0[] = { 0x41, 0x4b, 0x45, 0x4f, 0xfc, 0x31, 0xc0, 0xfa, 0x8e, 0xd0, 0xbc, 0x00, 0x7c, 0xfb, 0x89, 0xe6, 0x89, 0xe7, 0x1e, 0x06, 0x8e, 0xd8, 0xbb, 0x13, 0x04, 0x8b, 0x07, 0x48, 0x89, 0x07, 0xc1, 0xe0, 0x06, 0x2d, 0xc0, 0x07, 0x8e, 0xc0, 0xb9, 0x00, 0x02, 0xf3, 0xa4, 0x50, 0x68, 0x30, 0x7c, 0xcb, 0x8e, 0xd8, 0x66, 0x31, 0xdb, 0x8e, 0xc3, 0x41, 0xba, 0x81, 0x00, 0xe8, 0x89, 0x00, 0x72, 0x6d, 0xbb, 0xbe, 0x7d, 0xb9, 0x04, 0x00, 0x26, 0x80, 0x3f, 0x00, 0x7c, 0x09, 0x75, 0x05, 0x83, 0xc3, 0x10, 0xe2, 0xf3, 0xeb, 0x58, 0xbe, 0x94, 0x7d, 0xe8, 0xda, 0x00, 0xe8, 0xca, 0x00, 0xba, 0x5a, 0x7d, 0xbe, 0x6e, 0x7d, 0xe8, 0xa0, 0x00, 0xb4, 0x01, 0xcd, 0x16, 0x75, 0x3d, 0xb4, 0x02, 0xcd, 0x16, 0x24, 0x04, 0x75, 0x38, 0x80, 0x3e, 0x93, 0x7d, 0x00, 0x7f, 0x0b, 0xbe, 0xb4, 0x7d, 0xe8, 0xb3, 0x00, 0xc6, 0x06, 0x93, 0x7d, 0x12, 0x80, 0x3e, 0x92, 0x7d, 0x00, 0x75, 0xd9, 0xe8, 0x89, 0x00, 0xc6, 0x06, 0xbe, 0x7d, 0x81, 0x68, 0x80, 0x00, 0xba, 0x72, 0x7d, 0xbe, 0x7e, 0x7d, 0xe8, 0x65, 0x00, 0x5a, 0x07, 0x1f, 0xea, 0x00, 0x7c, 0x00, 0x00, 0xe8, 0x6d, 0x00, 0xe8, 0x78, 0x00, 0xbb, 0xbe, 0x7d, 0x8b, 0x17, 0x52, 0xb2, 0x80, 0x8b, 0x4f, 0x02, 0x66, 0x8b, 0x5f, 0x08, 0xe8, 0x05, 0x00, 0x73, 0xd5, 0x07, 0x1f, 0xcb, 0x60, 0xb4, 0x41, 0xbb, 0xaa, 0x55, 0xcd, 0x13, 0x72, 0x2c, 0x81, 0xfb, 0x55, 0xaa, 0x75, 0x26, 0xf7, 0xc1, 0x01, 0x00, 0x74, 0x20, 0x61, 0x1e, 0x66, 0x31, 0xc0, 0x8e, 0xd8, 0x66, 0x50, 0x66, 0x53, 0x50, 0x68, 0x00, 0x7c, 0x40, 0x50, 0x6a, 0x10, 0x89, 0xe6, 0xb4, 0x42, 0xcd, 0x13, 0x9f, 0x83, 0xc4, 0x10, 0x9e, 0x1f, 0xc3, 0x61, 0xbb, 0x00, 0x7c, 0xb8, 0x01, 0x02, 0xcd, 0x13, 0xc3, 0xfa, 0x8b, 0x1c, 0x26, 0x66, 0x8b, 0x07, 0x66, 0x89, 0x04, 0x26, 0x89, 0x17, 0x26, 0x8c, 0x4f, 0x02, 0xfb, 0xc3, 0xfa, 0xbb, 0x20, 0x00, 0x66, 0xa1, 0x6e, 0x7d, 0x26, 0x66, 0x89, 0x07, 0xfb, 0xc3, 0xb4, 0x01, 0xcd, 0x16, 0x74, 0x06, 0xb4, 0x00, 0xcd, 0x16, 0xe2, 0xf4, 0xc3, 0xac, 0x3c, 0x00, 0x74, 0x09, 0xb4, 0x0e, 0xbb, 0x07, 0x00, 0xcd, 0x10, 0xeb, 0xf2, 0xc3, 0x50, 0x2e, 0xa0, 0xbe, 0x7d, 0x80, 0xfa, 0x80, 0x75, 0x04, 0x88, 0xc2, 0xeb, 0x06, 0x38, 0xc2, 0x75, 0x02, 0xb2, 0x80, 0x58, 0xc3, 0xfa, 0x2e, 0x80, 0x3e, 0x92, 0x7d, 0x00, 0x74, 0x0a, 0x2e, 0xfe, 0x0e, 0x93, 0x7d, 0x2e, 0xfe, 0x0e, 0x92, 0x7d, 0xea, 0x20, 0x00, 0x00, 0x00, 0x9c, 0x2e, 0xfe, 0x06, 0x91, 0x7d, 0x75, 0x03, 0xe8, 0xc7, 0xff, 0x9a, 0x4c, 0x00, 0x00, 0x00, 0x9c, 0x2e, 0xfe, 0x0e, 0x91, 0x7d, 0x79, 0x03, 0xe8, 0xb7, 0xff, 0x9d, 0xca, 0x02, 0x00, 0xff, 0x49, 0x12, 0x0d, 0x0a, 0x50, 0x72, 0x65, 0x73, 0x73, 0x20, 0x61, 0x6e, 0x79, 0x20, 0x6b, 0x65, 0x79, 0x20, 0x74, 0x6f, 0x20, 0x62, 0x6f, 0x6f, 0x74, 0x20, 0x66, 0x72, 0x6f, 0x6d, 0x20, 0x55, 0x53, 0x42, 0x2e, 0x00, 0x00, 0x00 };
2,861
C
.h
44
63.090909
72
0.669507
pbatard/rufus
28,236
2,528
13
GPL-3.0
9/7/2024, 9:40:14 AM (Europe/Amsterdam)
false
false
false
true
false
false
false
true
4,988
mbr_95b.h
pbatard_rufus/src/ms-sys/inc/mbr_95b.h
/* First 446 bytes of MBR from Windows 95B, 98, 98SE and ME */ unsigned char mbr_95b_0x0[] = { 0x33, 0xc0, 0x8e, 0xd0, 0xbc, 0x00, 0x7c, 0xfb, 0x50, 0x07, 0x50, 0x1f, 0xfc, 0xbe, 0x1b, 0x7c, 0xbf, 0x1b, 0x06, 0x50, 0x57, 0xb9, 0xe5, 0x01, 0xf3, 0xa4, 0xcb, 0xbe, 0xbe, 0x07, 0xb1, 0x04, 0x38, 0x2c, 0x7c, 0x09, 0x75, 0x15, 0x83, 0xc6, 0x10, 0xe2, 0xf5, 0xcd, 0x18, 0x8b, 0x14, 0x8b, 0xee, 0x83, 0xc6, 0x10, 0x49, 0x74, 0x16, 0x38, 0x2c, 0x74, 0xf6, 0xbe, 0x10, 0x07, 0x4e, 0xac, 0x3c, 0x00, 0x74, 0xfa, 0xbb, 0x07, 0x00, 0xb4, 0x0e, 0xcd, 0x10, 0xeb, 0xf2, 0x89, 0x46, 0x25, 0x96, 0x8a, 0x46, 0x04, 0xb4, 0x06, 0x3c, 0x0e, 0x74, 0x11, 0xb4, 0x0b, 0x3c, 0x0c, 0x74, 0x05, 0x3a, 0xc4, 0x75, 0x2b, 0x40, 0xc6, 0x46, 0x25, 0x06, 0x75, 0x24, 0xbb, 0xaa, 0x55, 0x50, 0xb4, 0x41, 0xcd, 0x13, 0x58, 0x72, 0x16, 0x81, 0xfb, 0x55, 0xaa, 0x75, 0x10, 0xf6, 0xc1, 0x01, 0x74, 0x0b, 0x8a, 0xe0, 0x88, 0x56, 0x24, 0xc7, 0x06, 0xa1, 0x06, 0xeb, 0x1e, 0x88, 0x66, 0x04, 0xbf, 0x0a, 0x00, 0xb8, 0x01, 0x02, 0x8b, 0xdc, 0x33, 0xc9, 0x83, 0xff, 0x05, 0x7f, 0x03, 0x8b, 0x4e, 0x25, 0x03, 0x4e, 0x02, 0xcd, 0x13, 0x72, 0x29, 0xbe, 0x46, 0x07, 0x81, 0x3e, 0xfe, 0x7d, 0x55, 0xaa, 0x74, 0x5a, 0x83, 0xef, 0x05, 0x7f, 0xda, 0x85, 0xf6, 0x75, 0x83, 0xbe, 0x27, 0x07, 0xeb, 0x8a, 0x98, 0x91, 0x52, 0x99, 0x03, 0x46, 0x08, 0x13, 0x56, 0x0a, 0xe8, 0x12, 0x00, 0x5a, 0xeb, 0xd5, 0x4f, 0x74, 0xe4, 0x33, 0xc0, 0xcd, 0x13, 0xeb, 0xb8 }; /* Next 6 bytes used to write boot drive and time by some Windows OSs */ /* unsigned char mbr_95b_0x0da[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; */ unsigned char mbr_95b_0x0e0[] = { 0x56, 0x33, 0xf6, 0x56, 0x56, 0x52, 0x50, 0x06, 0x53, 0x51, 0xbe, 0x10, 0x00, 0x56, 0x8b, 0xf4, 0x50, 0x52, 0xb8, 0x00, 0x42, 0x8a, 0x56, 0x24, 0xcd, 0x13, 0x5a, 0x58, 0x8d, 0x64, 0x10, 0x72, 0x0a, 0x40, 0x75, 0x01, 0x42, 0x80, 0xc7, 0x02, 0xe2, 0xf7, 0xf8, 0x5e, 0xc3, 0xeb, 0x74, 0x49, 0x6e, 0x76, 0x61, 0x6c, 0x69, 0x64, 0x20, 0x70, 0x61, 0x72, 0x74, 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x74, 0x61, 0x62, 0x6c, 0x65, 0x00, 0x45, 0x72, 0x72, 0x6f, 0x72, 0x20, 0x6c, 0x6f, 0x61, 0x64, 0x69, 0x6e, 0x67, 0x20, 0x6f, 0x70, 0x65, 0x72, 0x61, 0x74, 0x69, 0x6e, 0x67, 0x20, 0x73, 0x79, 0x73, 0x74, 0x65, 0x6d, 0x00, 0x4d, 0x69, 0x73, 0x73, 0x69, 0x6e, 0x67, 0x20, 0x6f, 0x70, 0x65, 0x72, 0x61, 0x74, 0x69, 0x6e, 0x67, 0x20, 0x73, 0x79, 0x73, 0x74, 0x65, 0x6d, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x8b, 0xfc, 0x1e, 0x57, 0x8b, 0xf5, 0xcb, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; /* Next four bytes used for Windows Disk Signature / Drive serial number */ /* unsigned char mbr_95b_0x1b8[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; */
3,232
C
.h
56
53.321429
75
0.638224
pbatard/rufus
28,236
2,528
13
GPL-3.0
9/7/2024, 9:40:14 AM (Europe/Amsterdam)
false
false
false
true
false
false
false
true
4,989
br_fat16ros_0x0.h
pbatard_rufus/src/ms-sys/inc/br_fat16ros_0x0.h
unsigned char br_fat16_0x0[] = { 0xeb, 0x71, 0x90, 0x46, 0x72, 0x4c, 0x64, 0x72, 0x31, 0x2e, 0x30 };
103
C
.h
3
32.666667
66
0.66
pbatard/rufus
28,236
2,528
13
GPL-3.0
9/7/2024, 9:40:14 AM (Europe/Amsterdam)
false
false
false
true
false
false
false
true
4,990
mbr_grub2.h
pbatard_rufus/src/ms-sys/inc/mbr_grub2.h
/* * First 432 bytes of MBR from Grub2 (boot.img), with 2 bytes NOPed @0x66 * as per grub2's setup.c comments: * If DEST_DRIVE is a hard disk, enable the workaround, which is * for buggy BIOSes which don't pass boot drive correctly. Instead, * they pass 0x00 or 0x01 even when booted from 0x80. */ unsigned char mbr_grub2_0x0[] = { 0xEB, 0x63, 0x90, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFA, 0x90, 0x90, 0xF6, 0xC2, 0x80, 0x74, 0x05, 0xF6, 0xC2, 0x70, 0x74, 0x02, 0xB2, 0x80, 0xEA, 0x79, 0x7C, 0x00, 0x00, 0x31, 0xC0, 0x8E, 0xD8, 0x8E, 0xD0, 0xBC, 0x00, 0x20, 0xFB, 0xA0, 0x64, 0x7C, 0x3C, 0xFF, 0x74, 0x02, 0x88, 0xC2, 0x52, 0xBE, 0x80, 0x7D, 0xE8, 0x17, 0x01, 0xBE, 0x05, 0x7C, 0xB4, 0x41, 0xBB, 0xAA, 0x55, 0xCD, 0x13, 0x5A, 0x52, 0x72, 0x3D, 0x81, 0xFB, 0x55, 0xAA, 0x75, 0x37, 0x83, 0xE1, 0x01, 0x74, 0x32, 0x31, 0xC0, 0x89, 0x44, 0x04, 0x40, 0x88, 0x44, 0xFF, 0x89, 0x44, 0x02, 0xC7, 0x04, 0x10, 0x00, 0x66, 0x8B, 0x1E, 0x5C, 0x7C, 0x66, 0x89, 0x5C, 0x08, 0x66, 0x8B, 0x1E, 0x60, 0x7C, 0x66, 0x89, 0x5C, 0x0C, 0xC7, 0x44, 0x06, 0x00, 0x70, 0xB4, 0x42, 0xCD, 0x13, 0x72, 0x05, 0xBB, 0x00, 0x70, 0xEB, 0x76, 0xB4, 0x08, 0xCD, 0x13, 0x73, 0x0D, 0x5A, 0x84, 0xD2, 0x0F, 0x83, 0xD8, 0x00, 0xBE, 0x8B, 0x7D, 0xE9, 0x82, 0x00, 0x66, 0x0F, 0xB6, 0xC6, 0x88, 0x64, 0xFF, 0x40, 0x66, 0x89, 0x44, 0x04, 0x0F, 0xB6, 0xD1, 0xC1, 0xE2, 0x02, 0x88, 0xE8, 0x88, 0xF4, 0x40, 0x89, 0x44, 0x08, 0x0F, 0xB6, 0xC2, 0xC0, 0xE8, 0x02, 0x66, 0x89, 0x04, 0x66, 0xA1, 0x60, 0x7C, 0x66, 0x09, 0xC0, 0x75, 0x4E, 0x66, 0xA1, 0x5C, 0x7C, 0x66, 0x31, 0xD2, 0x66, 0xF7, 0x34, 0x88, 0xD1, 0x31, 0xD2, 0x66, 0xF7, 0x74, 0x04, 0x3B, 0x44, 0x08, 0x7D, 0x37, 0xFE, 0xC1, 0x88, 0xC5, 0x30, 0xC0, 0xC1, 0xE8, 0x02, 0x08, 0xC1, 0x88, 0xD0, 0x5A, 0x88, 0xC6, 0xBB, 0x00, 0x70, 0x8E, 0xC3, 0x31, 0xDB, 0xB8, 0x01, 0x02, 0xCD, 0x13, 0x72, 0x1E, 0x8C, 0xC3, 0x60, 0x1E, 0xB9, 0x00, 0x01, 0x8E, 0xDB, 0x31, 0xF6, 0xBF, 0x00, 0x80, 0x8E, 0xC6, 0xFC, 0xF3, 0xA5, 0x1F, 0x61, 0xFF, 0x26, 0x5A, 0x7C, 0xBE, 0x86, 0x7D, 0xEB, 0x03, 0xBE, 0x95, 0x7D, 0xE8, 0x34, 0x00, 0xBE, 0x9A, 0x7D, 0xE8, 0x2E, 0x00, 0xCD, 0x18, 0xEB, 0xFE, 0x47, 0x52, 0x55, 0x42, 0x20, 0x00, 0x47, 0x65, 0x6F, 0x6D, 0x00, 0x48, 0x61, 0x72, 0x64, 0x20, 0x44, 0x69, 0x73, 0x6B, 0x00, 0x52, 0x65, 0x61, 0x64, 0x00, 0x20, 0x45, 0x72, 0x72, 0x6F, 0x72, 0x0D, 0x0A, 0x00, 0xBB, 0x01, 0x00, 0xB4, 0x0E, 0xCD, 0x10, 0xAC, 0x3C, 0x00, 0x75, 0xF4, 0xC3 };
2,975
C
.h
45
64.155556
73
0.672243
pbatard/rufus
28,236
2,528
13
GPL-3.0
9/7/2024, 9:40:14 AM (Europe/Amsterdam)
false
false
false
true
false
false
false
true
4,991
br_fat12_0x0.h
pbatard_rufus/src/ms-sys/inc/br_fat12_0x0.h
unsigned char br_fat12_0x0[] = { 0xeb, 0x3c, 0x90, 0x4d, 0x53, 0x57, 0x49, 0x4e, 0x34, 0x2e, 0x31 };
103
C
.h
3
32.666667
66
0.66
pbatard/rufus
28,236
2,528
13
GPL-3.0
9/7/2024, 9:40:14 AM (Europe/Amsterdam)
false
false
false
true
false
false
false
true
4,992
mbr_kolibri.h
pbatard_rufus/src/ms-sys/inc/mbr_kolibri.h
/* First 440 bytes of MBR from KolibriOS */ unsigned char mbr_kolibri_0x0[] = { 0x33, 0xC0, 0x8E, 0xD0, 0xBC, 0x00, 0x7C, 0xFB, 0x50, 0x07, 0x50, 0x1F, 0xFC, 0xBE, 0x1B, 0x7C, 0xBF, 0x1B, 0x06, 0x50, 0x57, 0xB9, 0xE5, 0x01, 0xF3, 0xA4, 0xCB, 0xBD, 0xBE, 0x07, 0xB1, 0x04, 0x38, 0x6E, 0x00, 0x7C, 0x09, 0x75, 0x13, 0x83, 0xC5, 0x10, 0xE2, 0xF4, 0xCD, 0x18, 0x8B, 0xF5, 0x83, 0xC6, 0x10, 0x49, 0x74, 0x19, 0x38, 0x2C, 0x74, 0xF6, 0xA0, 0xB5, 0x07, 0xB4, 0x07, 0x8B, 0xF0, 0xAC, 0x3C, 0x00, 0x74, 0xFC, 0xBB, 0x07, 0x00, 0xB4, 0x0E, 0xCD, 0x10, 0xEB, 0xF2, 0x88, 0x4E, 0x10, 0xE8, 0x46, 0x00, 0x73, 0x2A, 0xFE, 0x46, 0x10, 0x80, 0x7E, 0x04, 0x0B, 0x74, 0x0B, 0x80, 0x7E, 0x04, 0x0C, 0x74, 0x05, 0xA0, 0xB6, 0x07, 0x75, 0xD2, 0x80, 0x46, 0x02, 0x06, 0x83, 0x46, 0x08, 0x06, 0x83, 0x56, 0x0A, 0x00, 0xE8, 0x21, 0x00, 0x73, 0x05, 0xA0, 0xB6, 0x07, 0xEB, 0xBC, 0x81, 0x3E, 0xFE, 0x7D, 0x55, 0xAA, 0x74, 0x0B, 0x80, 0x7E, 0x10, 0x00, 0x74, 0xC8, 0xA0, 0xB7, 0x07, 0xEB, 0xA9, 0x8B, 0xFC, 0x1E, 0x57, 0x8B, 0xF5, 0xCB, 0xBF, 0x05, 0x00, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x60, 0xBB, 0xAA, 0x55, 0xB4, 0x41, 0xCD, 0x13, 0x72, 0x36, 0x81, 0xFB, 0x55, 0xAA, 0x75, 0x30, 0xF6, 0xC1, 0x01, 0x74, 0x2B, 0x61, 0x60, 0x6A, 0x00, 0x6A, 0x00, 0xFF, 0x76, 0x0A, 0xFF, 0x76, 0x08, 0x6A, 0x00, 0x68, 0x00, 0x7C, 0x6A, 0x01, 0x6A, 0x10, 0xB4, 0x42, 0x8B, 0xF4, 0xCD, 0x13, 0x61, 0x61, 0x73, 0x0E, 0x4F, 0x74, 0x0B, 0x32, 0xE4, 0x52, 0xCD, 0x13, 0x5A, 0x90, 0xEB, 0xD6, 0x61, 0xF9, 0xC3, 0x49, 0x6E, 0x76, 0x61, 0x6C, 0x69, 0x64, 0x20, 0x70, 0x61, 0x72, 0x74, 0x69, 0x74, 0x69, 0x6F, 0x6E, 0x20, 0x74, 0x61, 0x62, 0x6C, 0x65, 0x00, 0x45, 0x72, 0x72, 0x6F, 0x72, 0x20, 0x6C, 0x6F, 0x61, 0x64, 0x69, 0x6E, 0x67, 0x20, 0x6F, 0x70, 0x65, 0x72, 0x61, 0x74, 0x69, 0x6E, 0x67, 0x20, 0x73, 0x79, 0x73, 0x74, 0x65, 0x6D, 0x00, 0x4D, 0x69, 0x73, 0x73, 0x69, 0x6E, 0x67, 0x20, 0x6F, 0x70, 0x65, 0x72, 0x61, 0x74, 0x69, 0x6E, 0x67, 0x20, 0x73, 0x79, 0x73, 0x74, 0x65, 0x6D, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x2C, 0x44, 0x63 };
2,759
C
.h
40
67.05
72
0.667893
pbatard/rufus
28,236
2,528
13
GPL-3.0
9/7/2024, 9:40:14 AM (Europe/Amsterdam)
false
false
false
true
false
false
false
true
4,993
mbr_win7.h
pbatard_rufus/src/ms-sys/inc/mbr_win7.h
/* First 446 bytes of MBR from Windows 7 */ /* This is English version. Bytes 0x163 onwards vary with language. */ /* Last three bytes 1b5-1b7 point to language-specific messages. */ /* Support of other languages is an exercise for the reader! */ /* see: http://thestarman.pcministry.com/asm/mbr/W7MBR.htm */ #define MBR_WIN7_LANG_INDEP_LEN 0x163 unsigned char mbr_win7_0x0[] = { 0x33, 0xc0, 0x8e, 0xd0, 0xbc, 0x00, 0x7c, 0x8e, 0xc0, 0x8e, 0xd8, 0xbe, 0x00, 0x7c, 0xbf, 0x00, 0x06, 0xb9, 0x00, 0x02, 0xfc, 0xf3, 0xa4, 0x50, 0x68, 0x1c, 0x06, 0xcb, 0xfb, 0xb9, 0x04, 0x00, 0xbd, 0xbe, 0x07, 0x80, 0x7e, 0x00, 0x00, 0x7c, 0x0b, 0x0f, 0x85, 0x0e, 0x01, 0x83, 0xc5, 0x10, 0xe2, 0xf1, 0xcd, 0x18, 0x88, 0x56, 0x00, 0x55, 0xc6, 0x46, 0x11, 0x05, 0xc6, 0x46, 0x10, 0x00, 0xb4, 0x41, 0xbb, 0xaa, 0x55, 0xcd, 0x13, 0x5d, 0x72, 0x0f, 0x81, 0xfb, 0x55, 0xaa, 0x75, 0x09, 0xf7, 0xc1, 0x01, 0x00, 0x74, 0x03, 0xfe, 0x46, 0x10, 0x66, 0x60, 0x80, 0x7e, 0x10, 0x00, 0x74, 0x26, 0x66, 0x68, 0x00, 0x00, 0x00, 0x00, 0x66, 0xff, 0x76, 0x08, 0x68, 0x00, 0x00, 0x68, 0x00, 0x7c, 0x68, 0x01, 0x00, 0x68, 0x10, 0x00, 0xb4, 0x42, 0x8a, 0x56, 0x00, 0x8b, 0xf4, 0xcd, 0x13, 0x9f, 0x83, 0xc4, 0x10, 0x9e, 0xeb, 0x14, 0xb8, 0x01, 0x02, 0xbb, 0x00, 0x7c, 0x8a, 0x56, 0x00, 0x8a, 0x76, 0x01, 0x8a, 0x4e, 0x02, 0x8a, 0x6e, 0x03, 0xcd, 0x13, 0x66, 0x61, 0x73, 0x1c, 0xfe, 0x4e, 0x11, 0x75, 0x0c, 0x80, 0x7e, 0x00, 0x80, 0x0f, 0x84, 0x8a, 0x00, 0xb2, 0x80, 0xeb, 0x84, 0x55, 0x32, 0xe4, 0x8a, 0x56, 0x00, 0xcd, 0x13, 0x5d, 0xeb, 0x9e, 0x81, 0x3e, 0xfe, 0x7d, 0x55, 0xaa, 0x75, 0x6e, 0xff, 0x76, 0x00, 0xe8, 0x8d, 0x00, 0x75, 0x17, 0xfa, 0xb0, 0xd1, 0xe6, 0x64, 0xe8, 0x83, 0x00, 0xb0, 0xdf, 0xe6, 0x60, 0xe8, 0x7c, 0x00, 0xb0, 0xff, 0xe6, 0x64, 0xe8, 0x75, 0x00, 0xfb, 0xb8, 0x00, 0xbb, 0xcd, 0x1a, 0x66, 0x23, 0xc0, 0x75, 0x3b, 0x66, 0x81, 0xfb, 0x54, 0x43, 0x50, 0x41, 0x75, 0x32, 0x81, 0xf9, 0x02, 0x01, 0x72, 0x2c, 0x66, 0x68, 0x07, 0xbb, 0x00, 0x00, 0x66, 0x68, 0x00, 0x02, 0x00, 0x00, 0x66, 0x68, 0x08, 0x00, 0x00, 0x00, 0x66, 0x53, 0x66, 0x53, 0x66, 0x55, 0x66, 0x68, 0x00, 0x00, 0x00, 0x00, 0x66, 0x68, 0x00, 0x7c, 0x00, 0x00, 0x66, 0x61, 0x68, 0x00, 0x00, 0x07, 0xcd, 0x1a, 0x5a, 0x32, 0xf6, 0xea, 0x00, 0x7c, 0x00, 0x00, 0xcd, 0x18, 0xa0, 0xb7, 0x07, 0xeb, 0x08, 0xa0, 0xb6, 0x07, 0xeb, 0x03, 0xa0, 0xb5, 0x07, 0x32, 0xe4, 0x05, 0x00, 0x07, 0x8b, 0xf0, 0xac, 0x3c, 0x00, 0x74, 0x09, 0xbb, 0x07, 0x00, 0xb4, 0x0e, 0xcd, 0x10, 0xeb, 0xf2, 0xf4, 0xeb, 0xfd, 0x2b, 0xc9, 0xe4, 0x64, 0xeb, 0x00, 0x24, 0x02, 0xe0, 0xf8, 0x24, 0x02, 0xc3, 0x49, 0x6e, 0x76, 0x61, 0x6c, 0x69, 0x64, 0x20, 0x70, 0x61, 0x72, 0x74, 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x74, 0x61, 0x62, 0x6c, 0x65, 0x00, 0x45, 0x72, 0x72, 0x6f, 0x72, 0x20, 0x6c, 0x6f, 0x61, 0x64, 0x69, 0x6e, 0x67, 0x20, 0x6f, 0x70, 0x65, 0x72, 0x61, 0x74, 0x69, 0x6e, 0x67, 0x20, 0x73, 0x79, 0x73, 0x74, 0x65, 0x6d, 0x00, 0x4d, 0x69, 0x73, 0x73, 0x69, 0x6e, 0x67, 0x20, 0x6f, 0x70, 0x65, 0x72, 0x61, 0x74, 0x69, 0x6e, 0x67, 0x20, 0x73, 0x79, 0x73, 0x74, 0x65, 0x6d, 0x00, 0x00, 0x00, 0x63, 0x7b, 0x9a }; /* Next four bytes used for Windows Disk Signature / Drive serial number */ /* unsigned char mbr_win7_0x1b8[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; */
3,322
C
.h
52
60.461538
75
0.655046
pbatard/rufus
28,236
2,528
13
GPL-3.0
9/7/2024, 9:40:14 AM (Europe/Amsterdam)
false
false
false
true
false
false
false
true
4,994
br_fat32ros_0x52.h
pbatard_rufus/src/ms-sys/inc/br_fat32ros_0x52.h
unsigned char br_fat32ros_0x52[] = { 0x46, 0x41, 0x54, 0x33, 0x32, 0x20, 0x20, 0x20, 0x31, 0xc0, 0x8e, 0xd8, 0x8e, 0xc0, 0x8e, 0xd0, 0xbd, 0x00, 0x7c, 0xbc, 0x00, 0x7c, 0x80, 0xbe, 0x40, 0x00, 0xff, 0x75, 0x04, 0x88, 0x96, 0x40, 0x00, 0x83, 0xbe, 0x16, 0x00, 0x00, 0x75, 0x0f, 0x66, 0x83, 0xbe, 0x11, 0x00, 0x00, 0x75, 0x07, 0x83, 0xbe, 0x2a, 0x00, 0x00, 0x76, 0x03, 0xe9, 0x07, 0x01, 0xb8, 0x00, 0x08, 0x8a, 0x96, 0x40, 0x00, 0xcd, 0x13, 0x73, 0x05, 0xb9, 0xff, 0xff, 0x88, 0xce, 0x88, 0xeb, 0x88, 0xcf, 0xc0, 0xef, 0x06, 0x80, 0xe1, 0x3f, 0x66, 0x0f, 0xb6, 0xc6, 0x66, 0x0f, 0xb7, 0xdb, 0x66, 0x0f, 0xb6, 0xc9, 0x66, 0x40, 0x66, 0x43, 0x66, 0xf7, 0xe1, 0x66, 0xf7, 0xe3, 0x66, 0xa3, 0xb4, 0x7d, 0x66, 0xb8, 0x0e, 0x00, 0x00, 0x00, 0x66, 0x03, 0x86, 0x1c, 0x00, 0xb9, 0x01, 0x00, 0x31, 0xdb, 0x8e, 0xc3, 0xbb, 0x00, 0x7e, 0xe8, 0x03, 0x00, 0xe9, 0x25, 0x01, 0x06, 0x66, 0x3b, 0x06, 0xb4, 0x7d, 0x73, 0x1c, 0x66, 0x60, 0xb4, 0x41, 0xbb, 0xaa, 0x55, 0x8a, 0x96, 0x40, 0x00, 0xcd, 0x13, 0x72, 0x57, 0x81, 0xfb, 0x55, 0xaa, 0x75, 0x51, 0xf6, 0xc1, 0x01, 0x74, 0x4c, 0x66, 0x61, 0x66, 0x60, 0x83, 0xf9, 0x40, 0x76, 0x03, 0xb9, 0x40, 0x00, 0x89, 0x0e, 0x45, 0x7d, 0x6a, 0x00, 0x6a, 0x00, 0x66, 0x50, 0x06, 0x53, 0x51, 0x6a, 0x10, 0x89, 0xe6, 0x8a, 0x96, 0x40, 0x00, 0xb4, 0x42, 0xcd, 0x13, 0x72, 0x67, 0x83, 0xc4, 0x10, 0x66, 0x61, 0x53, 0x66, 0x8b, 0x1e, 0x45, 0x7d, 0x66, 0x01, 0xd8, 0x66, 0xc1, 0xe3, 0x05, 0x8c, 0xc2, 0x01, 0xda, 0x8e, 0xc2, 0x5b, 0x2b, 0x0e, 0x45, 0x7d, 0x75, 0xbc, 0x07, 0xc3, 0x00, 0x00, 0x00, 0x00, 0x66, 0x61, 0x66, 0x60, 0x66, 0x31, 0xd2, 0x66, 0x0f, 0xb7, 0x8e, 0x18, 0x00, 0x66, 0xf7, 0xf1, 0xfe, 0xc2, 0x88, 0xd1, 0x66, 0x89, 0xc2, 0x66, 0xc1, 0xea, 0x10, 0xf7, 0xb6, 0x1a, 0x00, 0x88, 0xd6, 0x8a, 0x96, 0x40, 0x00, 0x88, 0xc5, 0xd0, 0xcc, 0xd0, 0xcc, 0x08, 0xe1, 0xb8, 0x01, 0x02, 0xcd, 0x13, 0x72, 0x0e, 0x66, 0x61, 0x66, 0x40, 0x8c, 0xc2, 0x83, 0xc2, 0x20, 0x8e, 0xc2, 0xe2, 0xc1, 0xc3, 0xbe, 0xb8, 0x7d, 0xe8, 0x14, 0x00, 0xeb, 0x06, 0xbe, 0xc5, 0x7d, 0xe8, 0x0c, 0x00, 0xbe, 0xd9, 0x7d, 0xe8, 0x06, 0x00, 0x31, 0xc0, 0xcd, 0x16, 0xcd, 0x19, 0xac, 0x08, 0xc0, 0x74, 0x09, 0xb4, 0x0e, 0xbb, 0x07, 0x00, 0xcd, 0x10, 0xeb, 0xf2, 0xc3, 0x00, 0x00, 0x00, 0x00, 0x44, 0x69, 0x73, 0x6b, 0x20, 0x65, 0x72, 0x72, 0x6f, 0x72, 0x0d, 0x0a, 0x00, 0x46, 0x69, 0x6c, 0x65, 0x20, 0x73, 0x79, 0x73, 0x74, 0x65, 0x6d, 0x20, 0x65, 0x72, 0x72, 0x6f, 0x72, 0x0d, 0x0a, 0x00, 0x50, 0x72, 0x65, 0x73, 0x73, 0x20, 0x61, 0x6e, 0x79, 0x20, 0x6b, 0x65, 0x79, 0x20, 0x74, 0x6f, 0x20, 0x72, 0x65, 0x73, 0x74, 0x61, 0x72, 0x74, 0x0d, 0x0a, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x55, 0xaa, 0x52, 0x52, 0x61, 0x41, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x72, 0x72, 0x41, 0x61 };
5,624
C
.h
79
69.21519
72
0.666907
pbatard/rufus
28,236
2,528
13
GPL-3.0
9/7/2024, 9:40:14 AM (Europe/Amsterdam)
false
false
false
true
false
false
false
true
4,995
br.h
pbatard_rufus/src/ms-sys/inc/br.h
#ifndef BR_H #define BR_H #include <stdio.h> #include <stdint.h> /* Sets custom number of bytes per sector, default value is 512 */ void set_bytes_per_sector(unsigned long ulValue); /* Gets Windows Disk Signature from MBR */ uint32_t read_windows_disk_signature(FILE *fp); /* Sets a new Windows Disk Signature to MBR */ int write_windows_disk_signature(FILE *fp, uint32_t tWDS); /* Reads copy protect bytes after Windows Disk Signature from MBR */ uint16_t read_mbr_copy_protect_bytes(FILE *fp); const char *read_mbr_copy_protect_bytes_explained(FILE *fp); /* returns TRUE if the file has a boot record, otherwise FALSE. The file position will change when this function is called! */ int is_br(FILE *fp); /* returns TRUE if the file has a LILO boot record, otherwise FALSE. The file position will change when this function is called! */ int is_lilo_br(FILE *fp); /* returns TRUE if the file has a Microsoft dos master boot record, otherwise FALSE.The file position will change when this function is called! */ int is_dos_mbr(FILE *fp); /* returns TRUE if the file has a Microsoft dos master boot record with the undocumented F2 instruction, otherwise FALSE. The file position will change when this function is called! */ int is_dos_f2_mbr(FILE *fp); /* returns TRUE if the file has a Microsoft 95b master boot record, otherwise FALSE.The file position will change when this function is called! */ int is_95b_mbr(FILE *fp); /* returns TRUE if the file has a Microsoft 2000 master boot record, otherwise FALSE.The file position will change when this function is called! */ int is_2000_mbr(FILE *fp); /* returns TRUE if the file has a Microsoft Vista master boot record, otherwise FALSE.The file position will change when this function is called! */ int is_vista_mbr(FILE *fp); /* returns TRUE if the file has a Microsoft 7 master boot record, otherwise FALSE.The file position will change when this function is called! */ int is_win7_mbr(FILE *fp); /* returns TRUE if the file has a Rufus master boot record, otherwise FALSE.The file position will change when this function is called! */ int is_rufus_mbr(FILE *fp); /* returns TRUE if the file has a Rufus GPT master boot record, otherwise FALSE.The file position will change when this function is called! */ int is_rufus_gpt_mbr(FILE *fp); /* returns TRUE if the file has a ReactOS master boot record, otherwise FALSE.The file position will change when this function is called! */ int is_reactos_mbr(FILE *fp); /* returns TRUE if the file has a Grub4DOS master boot record, otherwise FALSE.The file position will change when this function is called! */ int is_grub4dos_mbr(FILE *fp); /* returns TRUE if the file has a Grub 2.0 master boot record, otherwise FALSE.The file position will change when this function is called! */ int is_grub2_mbr(FILE *fp); /* returns TRUE if the file has a KolibriOS master boot record, otherwise FALSE.The file position will change when this function is called! */ int is_kolibrios_mbr(FILE *fp); /* returns TRUE if the file has a syslinux master boot record, otherwise FALSE.The file position will change when this function is called! */ int is_syslinux_mbr(FILE *fp); /* returns TRUE if the file has a syslinux GPT master boot record, otherwise FALSE.The file position will change when this function is called! */ int is_syslinux_gpt_mbr(FILE *fp); /* returns TRUE if the file has a zeroed master boot record, otherwise FALSE.The file position will change when this function is called! */ int is_zero_mbr(FILE *fp); int is_zero_mbr_not_including_disk_signature_or_copy_protect(FILE *fp); /* Writes a dos master boot record to a file, returns TRUE on success, otherwise FALSE */ int write_dos_mbr(FILE *fp); /* Writes a 95b master boot record to a file, returns TRUE on success, otherwise FALSE */ int write_95b_mbr(FILE *fp); /* Writes a 2000 master boot record to a file, returns TRUE on success, otherwise FALSE */ int write_2000_mbr(FILE *fp); /* Writes a Vista master boot record to a file, returns TRUE on success, otherwise FALSE */ int write_vista_mbr(FILE *fp); /* Writes a Windows 7 master boot record to a file, returns TRUE on success, otherwise FALSE */ int write_win7_mbr(FILE *fp); /* Writes a Rufus master boot record to a file, returns TRUE on success, otherwise FALSE */ int write_rufus_mbr(FILE *fp); /* Writes a Rufus MSG master boot record to a file, returns TRUE on success, otherwise FALSE */ int write_rufus_msg_mbr(FILE *fp); /* Writes a ReactOS master boot record to a file, returns TRUE on success, otherwise FALSE */ int write_reactos_mbr(FILE *fp); /* Writes a Grub4DOS master boot record to a file, returns TRUE on success, otherwise FALSE */ int write_grub4dos_mbr(FILE *fp); /* Writes a Grub 2.0 master boot record to a file, returns TRUE on success, otherwise FALSE */ int write_grub2_mbr(FILE *fp); /* Writes a KolibriOS master boot record to a file, returns TRUE on success, otherwise FALSE */ int write_kolibrios_mbr(FILE *fp); /* Writes a syslinux master boot record to a file, returns TRUE on success, otherwise FALSE */ int write_syslinux_mbr(FILE *fp); /* Writes a syslinux GPT master boot record to a file, returns TRUE on success, otherwise FALSE */ int write_syslinux_gpt_mbr(FILE *fp); /* Writes an empty (zeroed) master boot record to a file, returns TRUE on success, otherwise FALSE */ int write_zero_mbr(FILE *fp); #endif
5,484
C
.h
109
48.091743
92
0.756276
pbatard/rufus
28,236
2,528
13
GPL-3.0
9/7/2024, 9:40:14 AM (Europe/Amsterdam)
false
false
false
true
false
false
false
true
4,996
mbr_zero.h
pbatard_rufus/src/ms-sys/inc/mbr_zero.h
/* First 446 bytes of a zeroed MBR*/ unsigned char mbr_zero_0x0[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
2,824
C
.h
41
66.02439
73
0.657923
pbatard/rufus
28,236
2,528
13
GPL-3.0
9/7/2024, 9:40:14 AM (Europe/Amsterdam)
false
false
false
true
false
false
false
true
4,997
br_fat16_0x3e.h
pbatard_rufus/src/ms-sys/inc/br_fat16_0x3e.h
unsigned char br_fat16_0x3e[] = { 0xfa, 0x33, 0xc9, 0x8e, 0xd1, 0xbc, 0xfc, 0x7b, 0x16, 0x07, 0xbd, 0x78, 0x00, 0xc5, 0x76, 0x00, 0x1e, 0x56, 0x16, 0x55, 0xbf, 0x22, 0x05, 0x89, 0x7e, 0x00, 0x89, 0x4e, 0x02, 0xb1, 0x0b, 0xfc, 0xf3, 0xa4, 0x06, 0x1f, 0xbd, 0x00, 0x7c, 0xc6, 0x45, 0xfe, 0x0f, 0x8b, 0x46, 0x18, 0x88, 0x45, 0xf9, 0x38, 0x4e, 0x24, 0x7d, 0x22, 0x8b, 0xc1, 0x99, 0xe8, 0x77, 0x01, 0x72, 0x1a, 0x83, 0xeb, 0x3a, 0x66, 0xa1, 0x1c, 0x7c, 0x66, 0x3b, 0x07, 0x8a, 0x57, 0xfc, 0x75, 0x06, 0x80, 0xca, 0x02, 0x88, 0x56, 0x02, 0x80, 0xc3, 0x10, 0x73, 0xed, 0x33, 0xc9, 0x8a, 0x46, 0x10, 0x98, 0xf7, 0x66, 0x16, 0x03, 0x46, 0x1c, 0x13, 0x56, 0x1e, 0x03, 0x46, 0x0e, 0x13, 0xd1, 0x8b, 0x76, 0x11, 0x60, 0x89, 0x46, 0xfc, 0x89, 0x56, 0xfe, 0xb8, 0x20, 0x00, 0xf7, 0xe6, 0x8b, 0x5e, 0x0b, 0x03, 0xc3, 0x48, 0xf7, 0xf3, 0x01, 0x46, 0xfc, 0x11, 0x4e, 0xfe, 0x61, 0xbf, 0x00, 0x07, 0xe8, 0x23, 0x01, 0x72, 0x39, 0x38, 0x2d, 0x74, 0x17, 0x60, 0xb1, 0x0b, 0xbe, 0xd8, 0x7d, 0xf3, 0xa6, 0x61, 0x74, 0x39, 0x4e, 0x74, 0x09, 0x83, 0xc7, 0x20, 0x3b, 0xfb, 0x72, 0xe7, 0xeb, 0xdd, 0xbe, 0x7f, 0x7d, 0xac, 0x98, 0x03, 0xf0, 0xac, 0x84, 0xc0, 0x74, 0x17, 0x3c, 0xff, 0x74, 0x09, 0xb4, 0x0e, 0xbb, 0x07, 0x00, 0xcd, 0x10, 0xeb, 0xee, 0xbe, 0x82, 0x7d, 0xeb, 0xe5, 0xbe, 0x80, 0x7d, 0xeb, 0xe0, 0x98, 0xcd, 0x16, 0x5e, 0x1f, 0x66, 0x8f, 0x04, 0xcd, 0x19, 0xbe, 0x81, 0x7d, 0x8b, 0x7d, 0x1a, 0x8d, 0x45, 0xfe, 0x8a, 0x4e, 0x0d, 0xf7, 0xe1, 0x03, 0x46, 0xfc, 0x13, 0x56, 0xfe, 0xb1, 0x04, 0xe8, 0xc1, 0x00, 0x72, 0xd6, 0xea, 0x00, 0x02, 0x70, 0x00, 0xb4, 0x42, 0xeb, 0x2d, 0x60, 0x66, 0x6a, 0x00, 0x52, 0x50, 0x06, 0x53, 0x6a, 0x01, 0x6a, 0x10, 0x8b, 0xf4, 0x74, 0xec, 0x91, 0x92, 0x33, 0xd2, 0xf7, 0x76, 0x18, 0x91, 0xf7, 0x76, 0x18, 0x42, 0x87, 0xca, 0xf7, 0x76, 0x1a, 0x8a, 0xf2, 0x8a, 0xe8, 0xc0, 0xcc, 0x02, 0x0a, 0xcc, 0xb8, 0x01, 0x02, 0x8a, 0x56, 0x24, 0xcd, 0x13, 0x8d, 0x64, 0x10, 0x61, 0x72, 0x0a, 0x40, 0x75, 0x01, 0x42, 0x03, 0x5e, 0x0b, 0x49, 0x75, 0x77, 0xc3, 0x03, 0x18, 0x01, 0x27, 0x0d, 0x0a, 0x49, 0x6e, 0x76, 0x61, 0x6c, 0x69, 0x64, 0x20, 0x73, 0x79, 0x73, 0x74, 0x65, 0x6d, 0x20, 0x64, 0x69, 0x73, 0x6b, 0xff, 0x0d, 0x0a, 0x44, 0x69, 0x73, 0x6b, 0x20, 0x49, 0x2f, 0x4f, 0x20, 0x65, 0x72, 0x72, 0x6f, 0x72, 0xff, 0x0d, 0x0a, 0x52, 0x65, 0x70, 0x6c, 0x61, 0x63, 0x65, 0x20, 0x74, 0x68, 0x65, 0x20, 0x64, 0x69, 0x73, 0x6b, 0x2c, 0x20, 0x61, 0x6e, 0x64, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x20, 0x70, 0x72, 0x65, 0x73, 0x73, 0x20, 0x61, 0x6e, 0x79, 0x20, 0x6b, 0x65, 0x79, 0x0d, 0x0a, 0x00, 0x00, 0x49, 0x4f, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x53, 0x59, 0x53, 0x4d, 0x53, 0x44, 0x4f, 0x53, 0x20, 0x20, 0x20, 0x53, 0x59, 0x53, 0x7f, 0x01, 0x00, 0x41, 0xbb, 0x00, 0x07, 0x80, 0x7e, 0x02, 0x0e, 0xe9, 0x40, 0xff, 0x00, 0x00, 0x55, 0xaa };
2,904
C
.h
31
87.258065
98
0.634749
pbatard/rufus
28,236
2,528
13
GPL-3.0
9/7/2024, 9:40:14 AM (Europe/Amsterdam)
false
false
false
true
false
false
false
true
4,998
br_ntfs_0x0.h
pbatard_rufus/src/ms-sys/inc/br_ntfs_0x0.h
unsigned char br_ntfs_0x0[] = { 0xEB, 0x52, 0x90, 0x4E, 0x54, 0x46, 0x53, 0x20, 0x20, 0x20, 0x20 };
102
C
.h
3
32.333333
66
0.656566
pbatard/rufus
28,236
2,528
13
GPL-3.0
9/7/2024, 9:40:14 AM (Europe/Amsterdam)
false
false
false
true
false
false
false
true
4,999
br_fat32nt_0x3f0.h
pbatard_rufus/src/ms-sys/inc/br_fat32nt_0x3f0.h
unsigned char br_fat32nt_0x3f0[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x55, 0xaa, 0xfa, 0x66, 0x0f, 0xb6, 0x46, 0x10, 0x66, 0x8b, 0x4e, 0x24, 0x66, 0xf7, 0xe1, 0x66, 0x03, 0x46, 0x1c, 0x66, 0x0f, 0xb7, 0x56, 0x0e, 0x66, 0x03, 0xc2, 0x33, 0xc9, 0x66, 0x89, 0x46, 0xfc, 0x66, 0xc7, 0x46, 0xf8, 0xff, 0xff, 0xff, 0xff, 0xfa, 0x66, 0x8b, 0x46, 0x2c, 0x66, 0x83, 0xf8, 0x02, 0x0f, 0x82, 0xcf, 0xfc, 0x66, 0x3d, 0xf8, 0xff, 0xff, 0x0f, 0x0f, 0x83, 0xc5, 0xfc, 0x66, 0x0f, 0xa4, 0xc2, 0x10, 0xfb, 0x52, 0x50, 0xfa, 0x66, 0xc1, 0xe0, 0x10, 0x66, 0x0f, 0xac, 0xd0, 0x10, 0x66, 0x83, 0xe8, 0x02, 0x66, 0x0f, 0xb6, 0x5e, 0x0d, 0x8b, 0xf3, 0x66, 0xf7, 0xe3, 0x66, 0x03, 0x46, 0xfc, 0x66, 0x0f, 0xa4, 0xc2, 0x10, 0xfb, 0xbb, 0x00, 0x07, 0x8b, 0xfb, 0xb9, 0x01, 0x00, 0xe8, 0xbe, 0xfc, 0x0f, 0x82, 0xaa, 0xfc, 0x38, 0x2d, 0x74, 0x1e, 0xb1, 0x0b, 0x56, 0xbe, 0xd8, 0x7d, 0xf3, 0xa6, 0x5e, 0x74, 0x19, 0x03, 0xf9, 0x83, 0xc7, 0x15, 0x3b, 0xfb, 0x72, 0xe8, 0x4e, 0x75, 0xd6, 0x58, 0x5a, 0xe8, 0x66, 0x00, 0x72, 0xab, 0x83, 0xc4, 0x04, 0xe9, 0x64, 0xfc, 0x83, 0xc4, 0x04, 0x8b, 0x75, 0x09, 0x8b, 0x7d, 0x0f, 0x8b, 0xc6, 0xfa, 0x66, 0xc1, 0xe0, 0x10, 0x8b, 0xc7, 0x66, 0x83, 0xf8, 0x02, 0x72, 0x3b, 0x66, 0x3d, 0xf8, 0xff, 0xff, 0x0f, 0x73, 0x33, 0x66, 0x48, 0x66, 0x48, 0x66, 0x0f, 0xb6, 0x4e, 0x0d, 0x66, 0xf7, 0xe1, 0x66, 0x03, 0x46, 0xfc, 0x66, 0x0f, 0xa4, 0xc2, 0x10, 0xfb, 0xbb, 0x00, 0x07, 0x53, 0xb9, 0x04, 0x00, 0xe8, 0x52, 0xfc, 0x5b, 0x0f, 0x82, 0x3d, 0xfc, 0x81, 0x3f, 0x4d, 0x5a, 0x75, 0x08, 0x81, 0xbf, 0x00, 0x02, 0x42, 0x4a, 0x74, 0x06, 0xbe, 0x80, 0x7d, 0xe9, 0x0e, 0xfc, 0xea, 0x00, 0x02, 0x70, 0x00, 0x03, 0xc0, 0x13, 0xd2, 0x03, 0xc0, 0x13, 0xd2, 0xe8, 0x18, 0x00, 0xfa, 0x26, 0x66, 0x8b, 0x01, 0x66, 0x25, 0xff, 0xff, 0xff, 0x0f, 0x66, 0x0f, 0xa4, 0xc2, 0x10, 0x66, 0x3d, 0xf8, 0xff, 0xff, 0x0f, 0xfb, 0xc3, 0xbf, 0x00, 0x7e, 0xfa, 0x66, 0xc1, 0xe0, 0x10, 0x66, 0x0f, 0xac, 0xd0, 0x10, 0x66, 0x0f, 0xb7, 0x4e, 0x0b, 0x66, 0x33, 0xd2, 0x66, 0xf7, 0xf1, 0x66, 0x3b, 0x46, 0xf8, 0x74, 0x44, 0x66, 0x89, 0x46, 0xf8, 0x66, 0x03, 0x46, 0x1c, 0x66, 0x0f, 0xb7, 0x4e, 0x0e, 0x66, 0x03, 0xc1, 0x66, 0x0f, 0xb7, 0x5e, 0x28, 0x83, 0xe3, 0x0f, 0x74, 0x16, 0x3a, 0x5e, 0x10, 0x0f, 0x83, 0xa4, 0xfb, 0x52, 0x66, 0x8b, 0xc8, 0x66, 0x8b, 0x46, 0x24, 0x66, 0xf7, 0xe3, 0x66, 0x03, 0xc1, 0x5a, 0x52, 0x66, 0x0f, 0xa4, 0xc2, 0x10, 0xfb, 0x8b, 0xdf, 0xb9, 0x01, 0x00, 0xe8, 0xb4, 0xfb, 0x5a, 0x0f, 0x82, 0x9f, 0xfb, 0xfb, 0x8b, 0xda, 0xc3, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x55, 0xaa };
3,295
C
.h
46
68.717391
73
0.658049
pbatard/rufus
28,236
2,528
13
GPL-3.0
9/7/2024, 9:40:14 AM (Europe/Amsterdam)
false
false
false
true
false
false
false
true
5,000
br_ntfs_0x54.h
pbatard_rufus/src/ms-sys/inc/br_ntfs_0x54.h
unsigned char br_ntfs_0x54[] = { 0xFA, 0x33, 0xC0, 0x8E, 0xD0, 0xBC, 0x00, 0x7C, 0xFB, 0x68, 0xC0, 0x07, 0x1F, 0x1E, 0x68, 0x66, 0x00, 0xCB, 0x88, 0x16, 0x0E, 0x00, 0x66, 0x81, 0x3E, 0x03, 0x00, 0x4E, 0x54, 0x46, 0x53, 0x75, 0x15, 0xB4, 0x41, 0xBB, 0xAA, 0x55, 0xCD, 0x13, 0x72, 0x0C, 0x81, 0xFB, 0x55, 0xAA, 0x75, 0x06, 0xF7, 0xC1, 0x01, 0x00, 0x75, 0x03, 0xE9, 0xDD, 0x00, 0x1E, 0x83, 0xEC, 0x18, 0x68, 0x1A, 0x00, 0xB4, 0x48, 0x8A, 0x16, 0x0E, 0x00, 0x8B, 0xF4, 0x16, 0x1F, 0xCD, 0x13, 0x9F, 0x83, 0xC4, 0x18, 0x9E, 0x58, 0x1F, 0x72, 0xE1, 0x3B, 0x06, 0x0B, 0x00, 0x75, 0xDB, 0xA3, 0x0F, 0x00, 0xC1, 0x2E, 0x0F, 0x00, 0x04, 0x1E, 0x5A, 0x33, 0xDB, 0xB9, 0x00, 0x20, 0x2B, 0xC8, 0x66, 0xFF, 0x06, 0x11, 0x00, 0x03, 0x16, 0x0F, 0x00, 0x8E, 0xC2, 0xFF, 0x06, 0x16, 0x00, 0xE8, 0x4B, 0x00, 0x2B, 0xC8, 0x77, 0xEF, 0xB8, 0x00, 0xBB, 0xCD, 0x1A, 0x66, 0x23, 0xC0, 0x75, 0x2D, 0x66, 0x81, 0xFB, 0x54, 0x43, 0x50, 0x41, 0x75, 0x24, 0x81, 0xF9, 0x02, 0x01, 0x72, 0x1E, 0x16, 0x68, 0x07, 0xBB, 0x16, 0x68, 0x70, 0x0E, 0x16, 0x68, 0x09, 0x00, 0x66, 0x53, 0x66, 0x53, 0x66, 0x55, 0x16, 0x16, 0x16, 0x68, 0xB8, 0x01, 0x66, 0x61, 0x0E, 0x07, 0xCD, 0x1A, 0x33, 0xC0, 0xBF, 0x28, 0x10, 0xB9, 0xD8, 0x0F, 0xFC, 0xF3, 0xAA, 0xE9, 0x5F, 0x01, 0x90, 0x90, 0x66, 0x60, 0x1E, 0x06, 0x66, 0xA1, 0x11, 0x00, 0x66, 0x03, 0x06, 0x1C, 0x00, 0x1E, 0x66, 0x68, 0x00, 0x00, 0x00, 0x00, 0x66, 0x50, 0x06, 0x53, 0x68, 0x01, 0x00, 0x68, 0x10, 0x00, 0xB4, 0x42, 0x8A, 0x16, 0x0E, 0x00, 0x16, 0x1F, 0x8B, 0xF4, 0xCD, 0x13, 0x66, 0x59, 0x5B, 0x5A, 0x66, 0x59, 0x66, 0x59, 0x1F, 0x0F, 0x82, 0x16, 0x00, 0x66, 0xFF, 0x06, 0x11, 0x00, 0x03, 0x16, 0x0F, 0x00, 0x8E, 0xC2, 0xFF, 0x0E, 0x16, 0x00, 0x75, 0xBC, 0x07, 0x1F, 0x66, 0x61, 0xC3, 0xA0, 0xF8, 0x01, 0xE8, 0x09, 0x00, 0xA0, 0xFB, 0x01, 0xE8, 0x03, 0x00, 0xF4, 0xEB, 0xFD, 0xB4, 0x01, 0x8B, 0xF0, 0xAC, 0x3C, 0x00, 0x74, 0x09, 0xB4, 0x0E, 0xBB, 0x07, 0x00, 0xCD, 0x10, 0xEB, 0xF2, 0xC3, 0x0D, 0x0A, 0x41, 0x20, 0x64, 0x69, 0x73, 0x6B, 0x20, 0x72, 0x65, 0x61, 0x64, 0x20, 0x65, 0x72, 0x72, 0x6F, 0x72, 0x20, 0x6F, 0x63, 0x63, 0x75, 0x72, 0x72, 0x65, 0x64, 0x00, 0x0D, 0x0A, 0x42, 0x4F, 0x4F, 0x54, 0x4D, 0x47, 0x52, 0x20, 0x69, 0x73, 0x20, 0x6D, 0x69, 0x73, 0x73, 0x69, 0x6E, 0x67, 0x00, 0x0D, 0x0A, 0x42, 0x4F, 0x4F, 0x54, 0x4D, 0x47, 0x52, 0x20, 0x69, 0x73, 0x20, 0x63, 0x6F, 0x6D, 0x70, 0x72, 0x65, 0x73, 0x73, 0x65, 0x64, 0x00, 0x0D, 0x0A, 0x50, 0x72, 0x65, 0x73, 0x73, 0x20, 0x43, 0x74, 0x72, 0x6C, 0x2B, 0x41, 0x6C, 0x74, 0x2B, 0x44, 0x65, 0x6C, 0x20, 0x74, 0x6F, 0x20, 0x72, 0x65, 0x73, 0x74, 0x61, 0x72, 0x74, 0x0D, 0x0A, 0x00, 0x8C, 0xA9, 0xBE, 0xD6, 0x00, 0x00, 0x55, 0xAA, 0x07, 0x00, 0x42, 0x00, 0x4F, 0x00, 0x4F, 0x00, 0x54, 0x00, 0x4D, 0x00, 0x47, 0x00, 0x52, 0x00, 0x04, 0x00, 0x24, 0x00, 0x49, 0x00, 0x33, 0x00, 0x30, 0x00, 0x00, 0xD4, 0x00, 0x00, 0x00, 0x24, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xEB, 0x22, 0x90, 0x90, 0x05, 0x00, 0x4E, 0x00, 0x54, 0x00, 0x4C, 0x00, 0x44, 0x00, 0x52, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x66, 0x0F, 0xB7, 0x06, 0x0B, 0x00, 0x66, 0x0F, 0xB6, 0x1E, 0x0D, 0x00, 0x66, 0xF7, 0xE3, 0x66, 0xA3, 0x52, 0x02, 0x66, 0x8B, 0x0E, 0x40, 0x00, 0x80, 0xF9, 0x00, 0x0F, 0x8F, 0x0E, 0x00, 0xF6, 0xD9, 0x66, 0xB8, 0x01, 0x00, 0x00, 0x00, 0x66, 0xD3, 0xE0, 0xEB, 0x08, 0x90, 0x66, 0xA1, 0x52, 0x02, 0x66, 0xF7, 0xE1, 0x66, 0xA3, 0x66, 0x02, 0x66, 0x0F, 0xB7, 0x1E, 0x0B, 0x00, 0x66, 0x33, 0xD2, 0x66, 0xF7, 0xF3, 0x66, 0xA3, 0x56, 0x02, 0xE8, 0x95, 0x04, 0x66, 0x8B, 0x0E, 0x4E, 0x02, 0x66, 0x89, 0x0E, 0x26, 0x02, 0x66, 0x03, 0x0E, 0x66, 0x02, 0x66, 0x89, 0x0E, 0x2A, 0x02, 0x66, 0x03, 0x0E, 0x66, 0x02, 0x66, 0x89, 0x0E, 0x2E, 0x02, 0x66, 0x03, 0x0E, 0x66, 0x02, 0x66, 0x89, 0x0E, 0x3E, 0x02, 0x66, 0x03, 0x0E, 0x66, 0x02, 0x66, 0x89, 0x0E, 0x46, 0x02, 0x66, 0xB8, 0x90, 0x00, 0x00, 0x00, 0x66, 0x8B, 0x0E, 0x26, 0x02, 0xE8, 0x83, 0x09, 0x66, 0x0B, 0xC0, 0x0F, 0x84, 0x5E, 0xFE, 0x66, 0xA3, 0x32, 0x02, 0x66, 0xB8, 0xA0, 0x00, 0x00, 0x00, 0x66, 0x8B, 0x0E, 0x2A, 0x02, 0xE8, 0x6A, 0x09, 0x66, 0xA3, 0x36, 0x02, 0x66, 0xB8, 0xB0, 0x00, 0x00, 0x00, 0x66, 0x8B, 0x0E, 0x2E, 0x02, 0xE8, 0x58, 0x09, 0x66, 0xA3, 0x3A, 0x02, 0x66, 0xA1, 0x32, 0x02, 0x66, 0x0B, 0xC0, 0x0F, 0x84, 0x2B, 0xFE, 0x67, 0x80, 0x78, 0x08, 0x00, 0x0F, 0x85, 0x22, 0xFE, 0x67, 0x66, 0x8D, 0x50, 0x10, 0x67, 0x03, 0x42, 0x04, 0x67, 0x66, 0x0F, 0xB6, 0x48, 0x0C, 0x66, 0x89, 0x0E, 0x72, 0x02, 0x67, 0x66, 0x8B, 0x48, 0x08, 0x66, 0x89, 0x0E, 0x6E, 0x02, 0x66, 0xA1, 0x6E, 0x02, 0x66, 0x0F, 0xB7, 0x0E, 0x0B, 0x00, 0x66, 0x33, 0xD2, 0x66, 0xF7, 0xF1, 0x66, 0xA3, 0x76, 0x02, 0x66, 0xA1, 0x46, 0x02, 0x66, 0x03, 0x06, 0x6E, 0x02, 0x66, 0xA3, 0x4A, 0x02, 0x66, 0x83, 0x3E, 0x36, 0x02, 0x00, 0x0F, 0x84, 0x1D, 0x00, 0x66, 0x83, 0x3E, 0x3A, 0x02, 0x00, 0x0F, 0x84, 0xCF, 0xFD, 0x66, 0x8B, 0x1E, 0x3A, 0x02, 0x1E, 0x07, 0x66, 0x8B, 0x3E, 0x4A, 0x02, 0x66, 0xA1, 0x2E, 0x02, 0xE8, 0xE0, 0x01, 0x66, 0x0F, 0xB7, 0x0E, 0x00, 0x02, 0x66, 0xB8, 0x02, 0x02, 0x00, 0x00, 0xE8, 0x22, 0x08, 0x66, 0x0B, 0xC0, 0x0F, 0x85, 0x16, 0x00, 0x66, 0x0F, 0xB7, 0x0E, 0x5A, 0x02, 0x66, 0xB8, 0x5C, 0x02, 0x00, 0x00, 0xE8, 0x0C, 0x08, 0x66, 0x0B, 0xC0, 0x0F, 0x84, 0x42, 0x0C, 0x67, 0x66, 0x8B, 0x00, 0x1E, 0x07, 0x66, 0x8B, 0x3E, 0x3E, 0x02, 0xE8, 0x3F, 0x06, 0x66, 0xA1, 0x3E, 0x02, 0x66, 0xBB, 0x20, 0x00, 0x00, 0x00, 0x66, 0xB9, 0x00, 0x00, 0x00, 0x00, 0x66, 0xBA, 0x00, 0x00, 0x00, 0x00, 0xE8, 0xE4, 0x00, 0x66, 0x85, 0xC0, 0x0F, 0x85, 0x23, 0x00, 0x66, 0xA1, 0x3E, 0x02, 0x66, 0xBB, 0x80, 0x00, 0x00, 0x00, 0x66, 0xB9, 0x00, 0x00, 0x00, 0x00, 0x66, 0xBA, 0x00, 0x00, 0x00, 0x00, 0xE8, 0xC4, 0x00, 0x66, 0x0B, 0xC0, 0x0F, 0x85, 0x44, 0x00, 0xE9, 0xF1, 0x0B, 0x66, 0x33, 0xD2, 0x66, 0xB9, 0x80, 0x00, 0x00, 0x00, 0x66, 0xA1, 0x3E, 0x02, 0xE8, 0xCA, 0x08, 0x66, 0x0B, 0xC0, 0x0F, 0x84, 0xDA, 0x0B, 0x1E, 0x07, 0x66, 0x8B, 0x3E, 0x3E, 0x02, 0xE8, 0xDB, 0x05, 0x66, 0xA1, 0x3E, 0x02, 0x66, 0xBB, 0x80, 0x00, 0x00, 0x00, 0x66, 0xB9, 0x00, 0x00, 0x00, 0x00, 0x66, 0xBA, 0x00, 0x00, 0x00, 0x00, 0xE8, 0x80, 0x00, 0x66, 0x0B, 0xC0, 0x0F, 0x84, 0xB0, 0x0B, 0x67, 0x66, 0x0F, 0xB7, 0x58, 0x0C, 0x66, 0x81, 0xE3, 0xFF, 0x00, 0x00, 0x00, 0x0F, 0x85, 0xA5, 0x0B, 0x66, 0x8B, 0xD8, 0x68, 0x00, 0x20, 0x07, 0x66, 0x2B, 0xFF, 0x66, 0xA1, 0x3E, 0x02, 0xE8, 0x00, 0x01, 0x68, 0x00, 0x20, 0x07, 0x66, 0x2B, 0xFF, 0x66, 0xA1, 0x3E, 0x02, 0xE8, 0xAC, 0x0A, 0x8A, 0x16, 0x0E, 0x00, 0xB8, 0xE8, 0x03, 0x8E, 0xC0, 0x8D, 0x36, 0x0B, 0x00, 0x2B, 0xC0, 0x68, 0x00, 0x20, 0x50, 0xCB, 0x06, 0x1E, 0x66, 0x60, 0x66, 0x8B, 0xDA, 0x66, 0x0F, 0xB6, 0x0E, 0x0D, 0x00, 0x66, 0xF7, 0xE1, 0x66, 0xA3, 0x11, 0x00, 0x66, 0x8B, 0xC3, 0x66, 0xF7, 0xE1, 0xA3, 0x16, 0x00, 0x8B, 0xDF, 0x83, 0xE3, 0x0F, 0x8C, 0xC0, 0x66, 0xC1, 0xEF, 0x04, 0x03, 0xC7, 0x50, 0x07, 0xE8, 0x3E, 0xFC, 0x66, 0x61, 0x90, 0x1F, 0x07, 0xC3, 0x67, 0x03, 0x40, 0x14, 0x67, 0x66, 0x83, 0x38, 0xFF, 0x0F, 0x84, 0x4C, 0x00, 0x67, 0x66, 0x39, 0x18, 0x0F, 0x85, 0x33, 0x00, 0x66, 0x0B, 0xC9, 0x0F, 0x85, 0x0A, 0x00, 0x67, 0x80, 0x78, 0x09, 0x00, 0x0F, 0x85, 0x23, 0x00, 0xC3, 0x67, 0x3A, 0x48, 0x09, 0x0F, 0x85, 0x1A, 0x00, 0x66, 0x8B, 0xF0, 0x67, 0x03, 0x70, 0x0A, 0xE8, 0x97, 0x06, 0x66, 0x51, 0x1E, 0x07, 0x66, 0x8B, 0xFA, 0xF3, 0xA7, 0x66, 0x59, 0x0F, 0x85, 0x01, 0x00, 0xC3, 0x67, 0x66, 0x83, 0x78, 0x04, 0x00, 0x0F, 0x84, 0x07, 0x00, 0x67, 0x66, 0x03, 0x40, 0x04, 0xEB, 0xAB, 0x66, 0x2B, 0xC0, 0xC3, 0x66, 0x8B, 0xF3, 0xE8, 0x6C, 0x06, 0x67, 0x66, 0x03, 0x00, 0x67, 0xF7, 0x40, 0x0C, 0x02, 0x00, 0x0F, 0x85, 0x34, 0x00, 0x67, 0x66, 0x8D, 0x50, 0x10, 0x67, 0x3A, 0x4A, 0x40, 0x0F, 0x85, 0x18, 0x00, 0x67, 0x66, 0x8D, 0x72, 0x42, 0xE8, 0x49, 0x06, 0x66, 0x51, 0x1E, 0x07, 0x66, 0x8B, 0xFB, 0xF3, 0xA7, 0x66, 0x59, 0x0F, 0x85, 0x01, 0x00, 0xC3, 0x67, 0x83, 0x78, 0x08, 0x00, 0x0F, 0x84, 0x06, 0x00, 0x67, 0x03, 0x40, 0x08, 0xEB, 0xC2, 0x66, 0x33, 0xC0, 0xC3, 0x67, 0x80, 0x7B, 0x08, 0x00, 0x0F, 0x85, 0x1C, 0x00, 0x06, 0x1E, 0x66, 0x60, 0x67, 0x66, 0x8D, 0x53, 0x10, 0x67, 0x66, 0x8B, 0x0A, 0x66, 0x8B, 0xF3, 0x67, 0x03, 0x72, 0x04, 0xF3, 0xA4, 0x66, 0x61, 0x90, 0x1F, 0x07, 0xC3, 0x66, 0x50, 0x67, 0x66, 0x8D, 0x53, 0x10, 0x66, 0x85, 0xC0, 0x0F, 0x85, 0x0A, 0x00, 0x67, 0x66, 0x8B, 0x4A, 0x08, 0x66, 0x41, 0xEB, 0x11, 0x90, 0x67, 0x66, 0x8B, 0x42, 0x18, 0x66, 0x33, 0xD2, 0x66, 0xF7, 0x36, 0x52, 0x02, 0x66, 0x8B, 0xC8, 0x66, 0x2B, 0xC0, 0x66, 0x5E, 0xE8, 0x01, 0x00, 0xC3, 0x06, 0x1E, 0x66, 0x60, 0x67, 0x80, 0x7B, 0x08, 0x01, 0x0F, 0x84, 0x03, 0x00, 0xE9, 0x76, 0xFB, 0x66, 0x83, 0xF9, 0x00, 0x0F, 0x85, 0x06, 0x00, 0x66, 0x61, 0x90, 0x1F, 0x07, 0xC3, 0x66, 0x53, 0x66, 0x50, 0x66, 0x51, 0x66, 0x56, 0x66, 0x57, 0x06, 0xE8, 0x91, 0x04, 0x66, 0x8B, 0xD1, 0x07, 0x66, 0x5F, 0x66, 0x5E, 0x66, 0x59, 0x66, 0x85, 0xC0, 0x0F, 0x84, 0x34, 0x00, 0x66, 0x3B, 0xCA, 0x0F, 0x8D, 0x03, 0x00, 0x66, 0x8B, 0xD1, 0xE8, 0x82, 0xFE, 0x66, 0x2B, 0xCA, 0x66, 0x8B, 0xDA, 0x66, 0x8B, 0xC2, 0x66, 0x0F, 0xB6, 0x16, 0x0D, 0x00, 0x66, 0xF7, 0xE2, 0x66, 0x0F, 0xB7, 0x16, 0x0B, 0x00, 0x66, 0xF7, 0xE2, 0x66, 0x03, 0xF8, 0x66, 0x58, 0x66, 0x03, 0xC3, 0x66, 0x5B, 0xEB, 0x9F, 0x66, 0x85, 0xF6, 0x0F, 0x84, 0x0E, 0xFB, 0x66, 0x51, 0x66, 0x57, 0x06, 0x67, 0x66, 0x0F, 0xB6, 0x43, 0x09, 0x66, 0x85, 0xC0, 0x0F, 0x84, 0x20, 0x00, 0x66, 0xD1, 0xE0, 0x66, 0x2B, 0xE0, 0x66, 0x8B, 0xFC, 0x66, 0x54, 0x66, 0x56, 0x67, 0x66, 0x0F, 0xB7, 0x73, 0x0A, 0x66, 0x03, 0xF3, 0x66, 0x8B, 0xC8, 0xF3, 0xA4, 0x66, 0x5E, 0xEB, 0x03, 0x90, 0x66, 0x50, 0x66, 0x50, 0x67, 0x66, 0x8B, 0x03, 0x66, 0x50, 0x67, 0x66, 0x8B, 0x43, 0x18, 0x66, 0x50, 0x67, 0x66, 0x8B, 0x56, 0x20, 0x66, 0x85, 0xD2, 0x0F, 0x84, 0x0B, 0x00, 0x66, 0x8B, 0xFE, 0x1E, 0x07, 0x66, 0x8B, 0xC2, 0xE8, 0x71, 0x03, 0x66, 0x8B, 0xC6, 0x66, 0x5A, 0x66, 0x59, 0x66, 0x42, 0x66, 0x51, 0x66, 0x56, 0xE8, 0x3F, 0x06, 0x66, 0x85, 0xC0, 0x0F, 0x84, 0x9D, 0xFA, 0x66, 0x5E, 0x66, 0x59, 0x66, 0x8B, 0xFE, 0x1E, 0x07, 0xE8, 0x4E, 0x03, 0x66, 0x8B, 0xC6, 0x66, 0x8B, 0xD9, 0x66, 0x59, 0x66, 0x5A, 0x66, 0x51, 0x66, 0x56, 0x66, 0xD1, 0xE9, 0xE8, 0xF8, 0xFD, 0x66, 0x85, 0xC0, 0x0F, 0x84, 0x76, 0xFA, 0x66, 0x5E, 0x66, 0x59, 0x66, 0x03, 0xE1, 0x07, 0x66, 0x5F, 0x66, 0x59, 0x66, 0x8B, 0xD0, 0x66, 0x58, 0x66, 0x5B, 0x66, 0x8B, 0xDA, 0xE9, 0xF5, 0xFE, 0x06, 0x1E, 0x66, 0x60, 0x26, 0x67, 0x66, 0x0F, 0xB7, 0x5F, 0x04, 0x26, 0x67, 0x66, 0x0F, 0xB7, 0x4F, 0x06, 0x66, 0x0B, 0xC9, 0x0F, 0x84, 0x44, 0xFA, 0x66, 0x03, 0xDF, 0x66, 0x83, 0xC3, 0x02, 0x66, 0x81, 0xC7, 0xFE, 0x01, 0x00, 0x00, 0x66, 0x49, 0x66, 0x0B, 0xC9, 0x0F, 0x84, 0x17, 0x00, 0x26, 0x67, 0x8B, 0x03, 0x26, 0x67, 0x89, 0x07, 0x66, 0x83, 0xC3, 0x02, 0x66, 0x81, 0xC7, 0x00, 0x02, 0x00, 0x00, 0x66, 0x49, 0xEB, 0xE2, 0x66, 0x61, 0x90, 0x1F, 0x07, 0xC3, 0x06, 0x1E, 0x66, 0x60, 0x66, 0xB8, 0x01, 0x00, 0x00, 0x00, 0x66, 0xA3, 0x22, 0x02, 0x66, 0xA1, 0x1E, 0x02, 0x66, 0x03, 0x06, 0x66, 0x02, 0x66, 0xA3, 0x6A, 0x02, 0x66, 0x03, 0x06, 0x66, 0x02, 0x66, 0xA3, 0x4E, 0x02, 0x66, 0xA1, 0x30, 0x00, 0x66, 0x0F, 0xB6, 0x1E, 0x0D, 0x00, 0x66, 0xF7, 0xE3, 0x66, 0x8B, 0x1E, 0x4E, 0x02, 0x66, 0x89, 0x07, 0x66, 0xA3, 0x11, 0x00, 0x83, 0xC3, 0x04, 0x66, 0xA1, 0x56, 0x02, 0x66, 0x89, 0x07, 0xA3, 0x16, 0x00, 0x83, 0xC3, 0x04, 0x66, 0x89, 0x1E, 0x4E, 0x02, 0x66, 0x8B, 0x1E, 0x1E, 0x02, 0x1E, 0x07, 0xE8, 0x67, 0xF9, 0x66, 0x8B, 0xFB, 0xE8, 0x51, 0xFF, 0x66, 0xA1, 0x1E, 0x02, 0x66, 0xBB, 0x20, 0x00, 0x00, 0x00, 0x66, 0xB9, 0x00, 0x00, 0x00, 0x00, 0x66, 0xBA, 0x00, 0x00, 0x00, 0x00, 0xE8, 0x10, 0xFD, 0x66, 0x0B, 0xC0, 0x0F, 0x84, 0x19, 0x01, 0x66, 0x8B, 0xD8, 0x1E, 0x07, 0x66, 0x8B, 0x3E, 0x1A, 0x02, 0x66, 0x33, 0xC0, 0xE8, 0xA2, 0xFD, 0x66, 0x8B, 0x1E, 0x1A, 0x02, 0x66, 0x81, 0x3F, 0x80, 0x00, 0x00, 0x00, 0x0F, 0x84, 0xEB, 0x00, 0x03, 0x5F, 0x04, 0xEB, 0xF0, 0x66, 0x53, 0x66, 0x8B, 0x47, 0x10, 0x66, 0xF7, 0x26, 0x56, 0x02, 0x66, 0x50, 0x66, 0x33, 0xD2, 0x66, 0x0F, 0xB6, 0x1E, 0x0D, 0x00, 0x66, 0xF7, 0xF3, 0x66, 0x52, 0xE8, 0xDC, 0x00, 0x66, 0x0B, 0xC0, 0x0F, 0x84, 0x44, 0xF9, 0x66, 0x8B, 0x0E, 0x56, 0x02, 0x66, 0x0F, 0xB6, 0x1E, 0x0D, 0x00, 0x66, 0xF7, 0xE3, 0x66, 0x5A, 0x66, 0x03, 0xC2, 0x66, 0x8B, 0x1E, 0x4E, 0x02, 0x66, 0x89, 0x07, 0x83, 0xC3, 0x04, 0x66, 0x0F, 0xB6, 0x06, 0x0D, 0x00, 0x66, 0x2B, 0xC2, 0x66, 0x3B, 0xC1, 0x0F, 0x86, 0x03, 0x00, 0x66, 0x8B, 0xC1, 0x66, 0x89, 0x07, 0x66, 0x2B, 0xC8, 0x66, 0x5A, 0x0F, 0x84, 0x75, 0x00, 0x66, 0x03, 0xC2, 0x66, 0x50, 0x66, 0x33, 0xD2, 0x66, 0x0F, 0xB6, 0x1E, 0x0D, 0x00, 0x66, 0xF7, 0xF3, 0x66, 0x51, 0xE8, 0x82, 0x00, 0x66, 0x59, 0x66, 0x0B, 0xC0, 0x0F, 0x84, 0xE8, 0xF8, 0x66, 0x0F, 0xB6, 0x1E, 0x0D, 0x00, 0x66, 0xF7, 0xE3, 0x66, 0x8B, 0x1E, 0x4E, 0x02, 0x66, 0x8B, 0x17, 0x83, 0xC3, 0x04, 0x66, 0x03, 0x17, 0x66, 0x3B, 0xD0, 0x0F, 0x85, 0x15, 0x00, 0x66, 0x0F, 0xB6, 0x06, 0x0D, 0x00, 0x66, 0x3B, 0xC1, 0x0F, 0x86, 0x03, 0x00, 0x66, 0x8B, 0xC1, 0x66, 0x01, 0x07, 0xEB, 0xA5, 0x83, 0xC3, 0x04, 0x66, 0x89, 0x1E, 0x4E, 0x02, 0x66, 0x89, 0x07, 0x83, 0xC3, 0x04, 0x66, 0x0F, 0xB6, 0x06, 0x0D, 0x00, 0x66, 0x3B, 0xC1, 0x0F, 0x86, 0x03, 0x00, 0x66, 0x8B, 0xC1, 0x66, 0x89, 0x07, 0xEB, 0x82, 0x83, 0xC3, 0x04, 0x66, 0xFF, 0x06, 0x22, 0x02, 0x66, 0x89, 0x1E, 0x4E, 0x02, 0x66, 0x5B, 0x03, 0x5F, 0x04, 0x66, 0x81, 0x3F, 0x80, 0x00, 0x00, 0x00, 0x0F, 0x84, 0x0C, 0xFF, 0x66, 0x61, 0x90, 0x1F, 0x07, 0xC3, 0x66, 0x8B, 0xD0, 0x66, 0x8B, 0x0E, 0x22, 0x02, 0x66, 0x8B, 0x36, 0x6A, 0x02, 0x66, 0x03, 0x36, 0x66, 0x02, 0x66, 0x52, 0x66, 0x51, 0x66, 0x52, 0x66, 0x8B, 0x1E, 0x6A, 0x02, 0x66, 0x8B, 0x3E, 0x56, 0x02, 0x66, 0x8B, 0x04, 0x66, 0xA3, 0x11, 0x00, 0x83, 0xC6, 0x04, 0x66, 0x8B, 0x04, 0xA3, 0x16, 0x00, 0x83, 0xC6, 0x04, 0x1E, 0x07, 0xE8, 0xE8, 0xF7, 0x66, 0x2B, 0xF8, 0x0F, 0x84, 0x08, 0x00, 0xF7, 0x26, 0x0B, 0x00, 0x03, 0xD8, 0xEB, 0xD9, 0x66, 0x8B, 0x3E, 0x6A, 0x02, 0x1E, 0x07, 0xE8, 0xBF, 0xFD, 0x66, 0xA1, 0x6A, 0x02, 0x66, 0xBB, 0x80, 0x00, 0x00, 0x00, 0x66, 0xB9, 0x00, 0x00, 0x00, 0x00, 0x66, 0x8B, 0xD1, 0xE8, 0x81, 0xFB, 0x66, 0x0B, 0xC0, 0x0F, 0x84, 0xFF, 0xF7, 0x66, 0x8B, 0xD8, 0x66, 0x58, 0x66, 0x56, 0xE8, 0x2C, 0x01, 0x66, 0x5E, 0x66, 0x0B, 0xC0, 0x0F, 0x84, 0x05, 0x00, 0x66, 0x5B, 0x66, 0x5B, 0xC3, 0x66, 0x59, 0x66, 0x5A, 0xE2, 0x84, 0x66, 0x33, 0xC0, 0xC3, 0x06, 0x1E, 0x66, 0x60, 0x66, 0x50, 0x66, 0x51, 0x66, 0x33, 0xD2, 0x66, 0x0F, 0xB6, 0x1E, 0x0D, 0x00, 0x66, 0xF7, 0xF3, 0x66, 0x52, 0x66, 0x57, 0xE8, 0x53, 0xFF, 0x66, 0x5F, 0x66, 0x0B, 0xC0, 0x0F, 0x84, 0xB9, 0xF7, 0x66, 0x0F, 0xB6, 0x1E, 0x0D, 0x00, 0x66, 0xF7, 0xE3, 0x66, 0x5A, 0x66, 0x03, 0xC2, 0x66, 0xA3, 0x11, 0x00, 0x66, 0x59, 0x66, 0x0F, 0xB6, 0x1E, 0x0D, 0x00, 0x66, 0x3B, 0xCB, 0x0F, 0x8E, 0x13, 0x00, 0x89, 0x1E, 0x16, 0x00, 0x66, 0x2B, 0xCB, 0x66, 0x58, 0x66, 0x03, 0xC3, 0x66, 0x50, 0x66, 0x51, 0xEB, 0x14, 0x90, 0x66, 0x58, 0x66, 0x03, 0xC1, 0x66, 0x50, 0x89, 0x0E, 0x16, 0x00, 0x66, 0xB9, 0x00, 0x00, 0x00, 0x00, 0x66, 0x51, 0x06, 0x66, 0x57, 0x8B, 0xDF, 0x83, 0xE3, 0x0F, 0x8C, 0xC0, 0x66, 0xC1, 0xEF, 0x04, 0x03, 0xC7, 0x50, 0x07, 0xE8, 0x10, 0xF7, 0x66, 0x5F, 0x07, 0x66, 0x03, 0x3E, 0x52, 0x02, 0x66, 0x59, 0x66, 0x58, 0x66, 0x83, 0xF9, 0x00, 0x0F, 0x8F, 0x70, 0xFF, 0x66, 0x61, 0x90, 0x1F, 0x07, 0xC3, 0x06, 0x1E, 0x66, 0x60, 0x66, 0xF7, 0x26, 0x56, 0x02, 0x66, 0x8B, 0x0E, 0x56, 0x02, 0xE8, 0x55, 0xFF, 0xE8, 0xD2, 0xFC, 0x66, 0x61, 0x90, 0x1F, 0x07, 0xC3, 0x06, 0x1E, 0x66, 0x60, 0x66, 0xF7, 0x26, 0x72, 0x02, 0x66, 0x8B, 0x1E, 0x36, 0x02, 0x66, 0x8B, 0x0E, 0x72, 0x02, 0x66, 0x8B, 0x36, 0x2A, 0x02, 0x1E, 0x07, 0x66, 0x8B, 0x3E, 0x46, 0x02, 0xE8, 0x81, 0xFB, 0xE8, 0xA7, 0xFC, 0x66, 0x61, 0x90, 0x1F, 0x07, 0xC3, 0x66, 0x50, 0x66, 0x53, 0x66, 0x51, 0x66, 0x8B, 0x1E, 0x4A, 0x02, 0x66, 0x8B, 0xC8, 0x66, 0xC1, 0xE8, 0x03, 0x66, 0x83, 0xE1, 0x07, 0x66, 0x03, 0xD8, 0x66, 0xB8, 0x01, 0x00, 0x00, 0x00, 0x66, 0xD3, 0xE0, 0x67, 0x84, 0x03, 0x0F, 0x84, 0x04, 0x00, 0xF8, 0xEB, 0x02, 0x90, 0xF9, 0x66, 0x59, 0x66, 0x5B, 0x66, 0x58, 0xC3, 0x67, 0x80, 0x7B, 0x08, 0x01, 0x0F, 0x84, 0x04, 0x00, 0x66, 0x2B, 0xC0, 0xC3, 0x67, 0x66, 0x8D, 0x73, 0x10, 0x67, 0x66, 0x8B, 0x56, 0x08, 0x66, 0x3B, 0xC2, 0x0F, 0x87, 0x0B, 0x00, 0x67, 0x66, 0x8B, 0x16, 0x66, 0x3B, 0xC2, 0x0F, 0x83, 0x04, 0x00, 0x66, 0x2B, 0xC0, 0xC3, 0x67, 0x03, 0x5E, 0x10, 0x66, 0x2B, 0xF6, 0x67, 0x80, 0x3B, 0x00, 0x0F, 0x84, 0x3E, 0x00, 0xE8, 0x81, 0x00, 0x66, 0x03, 0xF1, 0xE8, 0x39, 0x00, 0x66, 0x03, 0xCA, 0x66, 0x3B, 0xC1, 0x0F, 0x8C, 0x21, 0x00, 0x66, 0x8B, 0xD1, 0x66, 0x50, 0x67, 0x66, 0x0F, 0xB6, 0x0B, 0x66, 0x8B, 0xC1, 0x66, 0x83, 0xE0, 0x0F, 0x66, 0xC1, 0xE9, 0x04, 0x66, 0x03, 0xD9, 0x66, 0x03, 0xD8, 0x66, 0x43, 0x66, 0x58, 0xEB, 0xC4, 0x66, 0x2B, 0xC8, 0x66, 0x2B, 0xC2, 0x66, 0x03, 0xC6, 0xC3, 0x66, 0x2B, 0xC0, 0xC3, 0x66, 0x2B, 0xC9, 0x67, 0x8A, 0x0B, 0x80, 0xE1, 0x0F, 0x66, 0x83, 0xF9, 0x00, 0x0F, 0x85, 0x04, 0x00, 0x66, 0x2B, 0xC9, 0xC3, 0x66, 0x53, 0x66, 0x52, 0x66, 0x03, 0xD9, 0x67, 0x66, 0x0F, 0xBE, 0x13, 0x66, 0x49, 0x66, 0x4B, 0x66, 0x83, 0xF9, 0x00, 0x0F, 0x84, 0x0D, 0x00, 0x66, 0xC1, 0xE2, 0x08, 0x67, 0x8A, 0x13, 0x66, 0x4B, 0x66, 0x49, 0xEB, 0xEB, 0x66, 0x8B, 0xCA, 0x66, 0x5A, 0x66, 0x5B, 0xC3, 0x66, 0x53, 0x66, 0x52, 0x66, 0x2B, 0xD2, 0x67, 0x8A, 0x13, 0x66, 0x83, 0xE2, 0x0F, 0x66, 0x2B, 0xC9, 0x67, 0x8A, 0x0B, 0xC0, 0xE9, 0x04, 0x66, 0x83, 0xF9, 0x00, 0x0F, 0x85, 0x08, 0x00, 0x66, 0x2B, 0xC9, 0x66, 0x5A, 0x66, 0x5B, 0xC3, 0x66, 0x03, 0xDA, 0x66, 0x03, 0xD9, 0x67, 0x66, 0x0F, 0xBE, 0x13, 0x66, 0x49, 0x66, 0x4B, 0x66, 0x83, 0xF9, 0x00, 0x0F, 0x84, 0x0D, 0x00, 0x66, 0xC1, 0xE2, 0x08, 0x67, 0x8A, 0x13, 0x66, 0x4B, 0x66, 0x49, 0xEB, 0xEB, 0x66, 0x8B, 0xCA, 0x66, 0x5A, 0x66, 0x5B, 0xC3, 0x66, 0x0B, 0xC9, 0x0F, 0x85, 0x01, 0x00, 0xC3, 0x66, 0x51, 0x66, 0x56, 0x67, 0x83, 0x3E, 0x61, 0x0F, 0x8C, 0x0C, 0x00, 0x67, 0x83, 0x3E, 0x7A, 0x0F, 0x8F, 0x04, 0x00, 0x67, 0x83, 0x2E, 0x20, 0x66, 0x83, 0xC6, 0x02, 0xE2, 0xE6, 0x66, 0x5E, 0x66, 0x59, 0xC3, 0x66, 0x50, 0x66, 0x51, 0x66, 0x8B, 0xD0, 0x66, 0xA1, 0x32, 0x02, 0x67, 0x66, 0x8D, 0x58, 0x10, 0x67, 0x03, 0x43, 0x04, 0x67, 0x66, 0x8D, 0x40, 0x10, 0x66, 0x8B, 0xDA, 0xE8, 0x44, 0xF9, 0x66, 0x0B, 0xC0, 0x0F, 0x84, 0x05, 0x00, 0x66, 0x59, 0x66, 0x59, 0xC3, 0x66, 0xA1, 0x36, 0x02, 0x66, 0x0B, 0xC0, 0x0F, 0x85, 0x08, 0x00, 0x66, 0x59, 0x66, 0x59, 0x66, 0x33, 0xC0, 0xC3, 0x66, 0x8B, 0x16, 0x36, 0x02, 0x67, 0x66, 0x8D, 0x52, 0x10, 0x67, 0x66, 0x8B, 0x42, 0x18, 0x66, 0x33, 0xD2, 0x66, 0xF7, 0x36, 0x6E, 0x02, 0x66, 0x33, 0xF6, 0x66, 0x50, 0x66, 0x56, 0x66, 0x58, 0x66, 0x5E, 0x66, 0x3B, 0xC6, 0x0F, 0x84, 0x3A, 0x00, 0x66, 0x56, 0x66, 0x40, 0x66, 0x50, 0x66, 0x48, 0xE8, 0x1B, 0xFE, 0x72, 0xE8, 0xE8, 0xEB, 0xFD, 0x66, 0x5A, 0x66, 0x5E, 0x66, 0x59, 0x66, 0x5B, 0x66, 0x53, 0x66, 0x51, 0x66, 0x56, 0x66, 0x52, 0x66, 0xA1, 0x46, 0x02, 0x67, 0x66, 0x8D, 0x40, 0x18, 0xE8, 0xD0, 0xF8, 0x66, 0x0B, 0xC0, 0x74, 0xC4, 0x66, 0x59, 0x66, 0x59, 0x66, 0x59, 0x66, 0x59, 0xC3, 0x66, 0x59, 0x66, 0x59, 0x66, 0x33, 0xC0, 0xC3, 0x66, 0x51, 0x66, 0x50, 0x66, 0xB8, 0x05, 0x00, 0x00, 0x00, 0x1E, 0x07, 0x66, 0x8B, 0xF9, 0xE8, 0x8D, 0xFD, 0x66, 0x8B, 0xC1, 0x66, 0xBB, 0x20, 0x00, 0x00, 0x00, 0x66, 0xB9, 0x00, 0x00, 0x00, 0x00, 0x66, 0xBA, 0x00, 0x00, 0x00, 0x00, 0xE8, 0x33, 0xF8, 0x66, 0x5B, 0x66, 0x59, 0x66, 0x85, 0xC0, 0x0F, 0x85, 0x15, 0x00, 0x66, 0x8B, 0xC1, 0x66, 0x0F, 0xB7, 0x0E, 0x10, 0x02, 0x66, 0xBA, 0x12, 0x02, 0x00, 0x00, 0xE8, 0x16, 0xF8, 0xEB, 0x33, 0x90, 0x66, 0x33, 0xD2, 0x66, 0x8B, 0xC1, 0x66, 0x8B, 0xCB, 0x66, 0x50, 0x66, 0x53, 0xE8, 0x23, 0x00, 0x66, 0x5B, 0x66, 0x5F, 0x66, 0x0B, 0xC0, 0x0F, 0x84, 0x17, 0x00, 0x1E, 0x07, 0xE8, 0x35, 0xFD, 0x66, 0x8B, 0xC7, 0x66, 0x0F, 0xB7, 0x0E, 0x10, 0x02, 0x66, 0xBA, 0x12, 0x02, 0x00, 0x00, 0xE8, 0xE1, 0xF7, 0xC3, 0x66, 0x52, 0x66, 0x51, 0x66, 0xBB, 0x20, 0x00, 0x00, 0x00, 0x66, 0xB9, 0x00, 0x00, 0x00, 0x00, 0x66, 0xBA, 0x00, 0x00, 0x00, 0x00, 0xE8, 0xC7, 0xF7, 0x66, 0x0B, 0xC0, 0x0F, 0x84, 0x63, 0x00, 0x66, 0x8B, 0xD8, 0x1E, 0x07, 0x66, 0x8B, 0x3E, 0x1A, 0x02, 0x66, 0x33, 0xC0, 0xE8, 0x59, 0xF8, 0x1E, 0x07, 0x66, 0x8B, 0x1E, 0x1A, 0x02, 0x66, 0x59, 0x66, 0x5A, 0x26, 0x66, 0x39, 0x0F, 0x0F, 0x85, 0x0C, 0x00, 0x26, 0x66, 0x39, 0x57, 0x08, 0x0F, 0x84, 0x31, 0x00, 0xEB, 0x13, 0x90, 0x26, 0x66, 0x83, 0x3F, 0xFF, 0x0F, 0x84, 0x2F, 0x00, 0x26, 0x83, 0x7F, 0x04, 0x00, 0x0F, 0x84, 0x26, 0x00, 0x26, 0x66, 0x0F, 0xB7, 0x47, 0x04, 0x03, 0xD8, 0x8B, 0xC3, 0x25, 0x00, 0x80, 0x74, 0xCB, 0x8C, 0xC0, 0x05, 0x00, 0x08, 0x8E, 0xC0, 0x81, 0xE3, 0xFF, 0x7F, 0xEB, 0xBE, 0x26, 0x66, 0x8B, 0x47, 0x10, 0xC3, 0x66, 0x59, 0x66, 0x5A, 0x66, 0x33, 0xC0, 0xC3, 0x66, 0x50, 0x66, 0x51, 0x66, 0x8B, 0xC7, 0x66, 0xC1, 0xE8, 0x04, 0x06, 0x59, 0x03, 0xC8, 0x51, 0x07, 0x66, 0x83, 0xE7, 0x0F, 0x66, 0x59, 0x66, 0x58, 0xC3, 0x60, 0x06, 0xBE, 0xBD, 0x0D, 0xBF, 0x00, 0x20, 0x1E, 0x07, 0xB9, 0x0D, 0x00, 0x90, 0xF3, 0xA5, 0x07, 0x61, 0xC3, 0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF, 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, 0xF0, 0xE1, 0xD2, 0xC3, 0x00, 0x00, 0x00, 0x00, 0x20, 0x20, 0x60, 0x8B, 0x36, 0x18, 0x20, 0x26, 0x8A, 0x05, 0x88, 0x04, 0x47, 0x46, 0x66, 0xFF, 0x06, 0x14, 0x20, 0x81, 0xFE, 0x60, 0x20, 0x75, 0x06, 0xE8, 0x5B, 0x00, 0xBE, 0x20, 0x20, 0xE2, 0xE6, 0x89, 0x36, 0x18, 0x20, 0x61, 0xC3, 0x66, 0x60, 0x8B, 0x36, 0x18, 0x20, 0xB0, 0x80, 0x88, 0x04, 0x46, 0x32, 0xC0, 0x81, 0xFE, 0x60, 0x20, 0x75, 0x06, 0xE8, 0x3A, 0x00, 0xBE, 0x20, 0x20, 0x81, 0xFE, 0x58, 0x20, 0x75, 0xE9, 0x66, 0x33, 0xC0, 0x66, 0xA3, 0x58, 0x20, 0x66, 0xA1, 0x14, 0x20, 0x66, 0xC1, 0xE0, 0x03, 0x66, 0x0F, 0xC8, 0x66, 0xA3, 0x5C, 0x20, 0xE8, 0x18, 0x00, 0xBB, 0x00, 0x20, 0x66, 0x8B, 0x07, 0x66, 0x0F, 0xC8, 0x66, 0x89, 0x07, 0x83, 0xC3, 0x04, 0x81, 0xFB, 0x34, 0x20, 0x75, 0xEE, 0x66, 0x61, 0xC3, 0x66, 0x60, 0xBB, 0x20, 0x20, 0x66, 0x8B, 0x07, 0x66, 0x0F, 0xC8, 0x66, 0x89, 0x07, 0x83, 0xC3, 0x04, 0x81, 0xFB, 0x60, 0x20, 0x75, 0xEE, 0xBB, 0x00, 0x20, 0x66, 0x8B, 0x0F, 0x66, 0x8B, 0x57, 0x04, 0x66, 0x8B, 0x77, 0x08, 0x66, 0x8B, 0x7F, 0x0C, 0x66, 0x8B, 0x6F, 0x10, 0xBB, 0x20, 0x20, 0xC7, 0x06, 0x1A, 0x20, 0x30, 0x0F, 0xC6, 0x06, 0x1C, 0x20, 0x14, 0x90, 0x53, 0x8B, 0x1E, 0x1A, 0x20, 0xFF, 0x17, 0x66, 0x03, 0x47, 0x02, 0x5B, 0x66, 0x03, 0xE8, 0x66, 0x03, 0x2F, 0x66, 0x8B, 0xC1, 0x66, 0xC1, 0xC0, 0x05, 0x66, 0x03, 0xC5, 0x66, 0x8B, 0xEF, 0x66, 0x8B, 0xFE, 0x66, 0x8B, 0xF2, 0x66, 0xC1, 0xC6, 0x1E, 0x66, 0x8B, 0xD1, 0x66, 0x8B, 0xC8, 0x66, 0x8B, 0x07, 0x66, 0x33, 0x47, 0x08, 0x66, 0x33, 0x47, 0x20, 0x66, 0x33, 0x47, 0x34, 0x66, 0xD1, 0xC0, 0x66, 0x89, 0x47, 0x40, 0x83, 0xC3, 0x04, 0xFE, 0x0E, 0x1C, 0x20, 0x75, 0xB2, 0x83, 0x06, 0x1A, 0x20, 0x06, 0x81, 0x3E, 0x1A, 0x20, 0x48, 0x0F, 0x75, 0x9F, 0xBB, 0x00, 0x20, 0x66, 0x01, 0x0F, 0x66, 0x01, 0x57, 0x04, 0x66, 0x01, 0x77, 0x08, 0x66, 0x01, 0x7F, 0x0C, 0x66, 0x01, 0x6F, 0x10, 0x66, 0x61, 0xC3, 0x66, 0x8B, 0xC6, 0x66, 0x33, 0xC7, 0x66, 0x23, 0xC2, 0x66, 0x33, 0xC7, 0xC3, 0x66, 0x8B, 0xC2, 0x66, 0x33, 0xC6, 0x66, 0x33, 0xC7, 0xC3, 0x66, 0x53, 0x66, 0x8B, 0xC2, 0x66, 0x23, 0xC6, 0x66, 0x8B, 0xDA, 0x66, 0x23, 0xDF, 0x66, 0x0B, 0xC3, 0x66, 0x8B, 0xDE, 0x66, 0x23, 0xDF, 0x66, 0x0B, 0xC3, 0x66, 0x5B, 0xC3, 0xFC, 0x0E, 0x99, 0x79, 0x82, 0x5A, 0x09, 0x0F, 0xA1, 0xEB, 0xD9, 0x6E, 0x13, 0x0F, 0xDC, 0xBC, 0x1B, 0x8F, 0x09, 0x0F, 0xD6, 0xC1, 0x62, 0xCA, 0x06, 0x1E, 0x66, 0x60, 0x66, 0x33, 0xDB, 0xB8, 0x00, 0xBB, 0xCD, 0x1A, 0x66, 0x23, 0xC0, 0x0F, 0x85, 0xBB, 0x00, 0x66, 0x81, 0xFB, 0x54, 0x43, 0x50, 0x41, 0x0F, 0x85, 0xB0, 0x00, 0x81, 0xF9, 0x02, 0x01, 0x0F, 0x82, 0xA8, 0x00, 0x66, 0x61, 0x90, 0x1F, 0x07, 0x06, 0x1E, 0x66, 0x60, 0x67, 0x80, 0x7B, 0x08, 0x00, 0x0F, 0x85, 0x0C, 0x00, 0x67, 0x66, 0x8D, 0x53, 0x10, 0x67, 0x66, 0x8B, 0x0A, 0xEB, 0x25, 0x90, 0x67, 0x66, 0x8D, 0x53, 0x10, 0x67, 0x66, 0x8B, 0x4A, 0x28, 0x66, 0x81, 0xF9, 0x00, 0x00, 0x08, 0x00, 0x0F, 0x83, 0x0C, 0x00, 0x67, 0x66, 0x8B, 0x42, 0x2C, 0x66, 0x23, 0xC0, 0x0F, 0x84, 0x03, 0x00, 0x66, 0x33, 0xC9, 0x0E, 0x1F, 0xE8, 0xF5, 0xFD, 0x66, 0x23, 0xC9, 0x0F, 0x84, 0x32, 0x00, 0x66, 0xBA, 0x00, 0x80, 0x00, 0x00, 0x66, 0x3B, 0xCA, 0x0F, 0x86, 0x1F, 0x00, 0x66, 0x2B, 0xCA, 0x06, 0x66, 0x51, 0x66, 0x57, 0x66, 0x52, 0x66, 0x8B, 0xCA, 0xE8, 0xB7, 0xFD, 0xE8, 0xFB, 0xFD, 0x66, 0x5A, 0x66, 0x5F, 0x66, 0x59, 0x07, 0x66, 0x03, 0xFA, 0xEB, 0xDA, 0xE8, 0xA5, 0xFD, 0xE8, 0xE9, 0xFD, 0xE8, 0x0B, 0xFE, 0x0E, 0x07, 0x66, 0xBB, 0x54, 0x43, 0x50, 0x41, 0x66, 0xBF, 0x00, 0x20, 0x00, 0x00, 0x66, 0xB9, 0x14, 0x00, 0x00, 0x00, 0x66, 0xB8, 0x07, 0xBB, 0x00, 0x00, 0x66, 0xBA, 0x0A, 0x00, 0x00, 0x00, 0x66, 0x33, 0xF6, 0xCD, 0x1A, 0x66, 0x61, 0x90, 0x1F, 0x07, 0xC3, 0xA0, 0xF9, 0x01, 0xE9, 0x4B, 0xF1, 0xA0, 0xFA, 0x01, 0xE9, 0x45, 0xF1 };
25,363
C
.h
340
70.608824
74
0.648603
pbatard/rufus
28,236
2,528
13
GPL-3.0
9/7/2024, 9:40:14 AM (Europe/Amsterdam)
false
false
false
true
false
false
false
true
5,001
mbr_grub.h
pbatard_rufus/src/ms-sys/inc/mbr_grub.h
/* * First 423 bytes of MBR from Grub4DOS (Converted from res/grub/grldr.mbr) */ unsigned char mbr_grub_0x0[] = { 0xEB, 0x5E, 0x90, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x00, 0x20, 0x39, 0xFF, 0xFF, 0x31, 0xDB, 0x8E, 0xD3, 0xBC, 0x80, 0x05, 0xE8, 0x00, 0x00, 0x5B, 0x81, 0xEB, 0x6A, 0x00, 0xC1, 0xEB, 0x04, 0x8C, 0xC8, 0x01, 0xC3, 0x53, 0x68, 0x7B, 0x00, 0xCB, 0x68, 0x00, 0x20, 0x17, 0xBC, 0x00, 0x90, 0x80, 0xFA, 0x00, 0x74, 0x02, 0xB2, 0x80, 0x16, 0x07, 0xB0, 0x10, 0x30, 0xF6, 0x31, 0xDB, 0xE8, 0xC2, 0x00, 0x72, 0x29, 0x0E, 0x1F, 0x31, 0xF6, 0x31, 0xFF, 0xB9, 0xDF, 0x00, 0xFC, 0xF3, 0xA5, 0xBB, 0xFC, 0x1F, 0x66, 0xB8, 0x47, 0x52, 0x55, 0xAA, 0x66, 0x39, 0x07, 0x75, 0x03, 0xE8, 0xB6, 0x19, 0xEA, 0xB8, 0x00, 0x00, 0x20, 0x16, 0x1F, 0x66, 0x39, 0x07, 0x74, 0x1F, 0x80, 0xF2, 0x80, 0x68, 0xC0, 0x07, 0x07, 0xB0, 0x10, 0x30, 0xF6, 0x31, 0xDB, 0xE8, 0x87, 0x00, 0x72, 0x05, 0xEA, 0x00, 0x00, 0xC0, 0x07, 0xBE, 0x92, 0x01, 0xE8, 0xAF, 0x00, 0xEB, 0xFE, 0xBE, 0xBE, 0x01, 0xE8, 0x14, 0x10, 0xF6, 0x06, 0xA4, 0x01, 0x80, 0x0F, 0x84, 0x8A, 0x19, 0x83, 0xC6, 0x0C, 0x81, 0xFE, 0xFE, 0x01, 0x72, 0xEB, 0x77, 0x2D, 0xF6, 0x06, 0xA7, 0x01, 0x01, 0x0F, 0x85, 0x3C, 0x17, 0x80, 0x0E, 0xA7, 0x01, 0x01, 0xF6, 0x06, 0xA7, 0x01, 0x02, 0x75, 0xD4, 0x68, 0x00, 0x0D, 0x07, 0xB0, 0x04, 0x31, 0xD2, 0x31, 0xDB, 0xE8, 0x3C, 0x00, 0x73, 0xC2, 0xBE, 0xCB, 0x1C, 0xE8, 0x69, 0x00, 0xE9, 0x18, 0x17, 0xF6, 0x06, 0xA7, 0x01, 0x01, 0x0F, 0x85, 0x0F, 0x17, 0x80, 0x0E, 0xA7, 0x01, 0x01, 0xE9, 0xF0, 0x16, 0x1E, 0x06, 0x52, 0x56, 0x57, 0x55, 0xF9, 0xCD, 0x13, 0x5D, 0x5F, 0x5E, 0x5A, 0x07, 0x1F, 0xC3, 0xFA, 0xB8, 0x00, 0x20, 0x8E, 0xD0, 0xBC, 0xDC, 0x8F, 0xFB, 0x66, 0x61, 0x07, 0x1F, 0xEB, 0x97, 0xB4, 0x02, 0xBF, 0x03, 0x00, 0xB9, 0x01, 0x00, 0x60, 0x50, 0x53, 0x51, 0xFE, 0xC8, 0x00, 0xC1, 0xD0, 0xE0, 0x00, 0xC7, 0xB0, 0x01, 0xE8, 0xC7, 0xFF, 0x59, 0x5B, 0x58, 0x72, 0x04, 0xFE, 0xC8, 0x75, 0xE7, 0x61, 0x73, 0x0B, 0x60, 0x31, 0xC0, 0xE8, 0xB5, 0xFF, 0x61, 0x4F, 0x75, 0xD9, 0xF9, 0xC3, 0xB4, 0x0E, 0xCD, 0x10, 0x2E, 0xAC, 0x3C, 0x00, 0x75, 0xF6, 0xC3, 0x0D, 0x0A, 0x4D, 0x69, 0x73, 0x73, 0x69, 0x6E, 0x67, 0x20, 0x68, 0x65, 0x6C, 0x70, 0x65, 0x72, 0x2E, 0x00, 0x00, 0x3F, 0xFF };
2,800
C
.h
41
63.731707
75
0.642262
pbatard/rufus
28,236
2,528
13
GPL-3.0
9/7/2024, 9:40:14 AM (Europe/Amsterdam)
false
false
false
true
false
false
false
true
5,005
br_fat32ros_0x3f0.h
pbatard_rufus/src/ms-sys/inc/br_fat32ros_0x3f0.h
unsigned char br_fat32ros_0x3f0[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x55, 0xaa };
140
C
.h
4
33
73
0.669118
pbatard/rufus
28,236
2,528
13
GPL-3.0
9/7/2024, 9:40:14 AM (Europe/Amsterdam)
false
false
false
true
false
false
false
true
5,006
br_fat16ros_0x3e.h
pbatard_rufus/src/ms-sys/inc/br_fat16ros_0x3e.h
unsigned char br_fat16_0x3e[] = { 0x46, 0x52, 0x45, 0x45, 0x4c, 0x44, 0x52, 0x20, 0x53, 0x59, 0x53, 0x4c, 0x6f, 0x61, 0x64, 0x20, 0x66, 0x61, 0x69, 0x6c, 0x65, 0x64, 0x21, 0x0d, 0x0a, 0x00, 0x50, 0x72, 0x65, 0x73, 0x73, 0x20, 0x61, 0x6e, 0x79, 0x20, 0x6b, 0x65, 0x79, 0x20, 0x74, 0x6f, 0x20, 0x72, 0x65, 0x62, 0x6f, 0x6f, 0x74, 0x2e, 0x2e, 0x2e, 0x00, 0x31, 0xc0, 0x8e, 0xd8, 0x8e, 0xd0, 0xbc, 0xe0, 0x7b, 0x89, 0xe5, 0xa0, 0x24, 0x7c, 0x3c, 0xff, 0x74, 0x02, 0x88, 0xc2, 0x88, 0x16, 0x24, 0x7c, 0x31, 0xff, 0xb4, 0x08, 0xcd, 0x13, 0x0f, 0x82, 0xb8, 0x00, 0x66, 0x0f, 0xb6, 0xdd, 0x88, 0xcf, 0xc0, 0xef, 0x06, 0x80, 0xe1, 0x3f, 0x66, 0x0f, 0xb6, 0xc9, 0x66, 0x0f, 0xb6, 0xc6, 0x66, 0x40, 0x66, 0x43, 0x66, 0xf7, 0xe1, 0x66, 0xf7, 0xe3, 0x66, 0x89, 0x46, 0x08, 0x66, 0x0f, 0xb7, 0x86, 0x2e, 0x00, 0x66, 0x03, 0x86, 0x3c, 0x00, 0x66, 0x0f, 0xb7, 0x8e, 0x36, 0x00, 0x66, 0x60, 0xbb, 0x00, 0x80, 0x8e, 0xc3, 0x31, 0xff, 0xe8, 0xb9, 0x00, 0x66, 0x61, 0x66, 0x89, 0xc3, 0x66, 0x0f, 0xb6, 0x86, 0x30, 0x00, 0x66, 0xf7, 0xe1, 0x66, 0x01, 0xd8, 0x66, 0x89, 0x46, 0x04, 0x66, 0x0f, 0xb7, 0x9e, 0x31, 0x00, 0x66, 0x83, 0xc3, 0x0f, 0x66, 0xc1, 0xeb, 0x04, 0x66, 0x01, 0xc3, 0x66, 0x89, 0x5e, 0x00, 0xbb, 0x00, 0x10, 0x8e, 0xc3, 0x31, 0xff, 0x31, 0xc9, 0x41, 0x06, 0xe8, 0x81, 0x00, 0x07, 0xba, 0x10, 0x00, 0x31, 0xdb, 0x89, 0xdf, 0x26, 0x38, 0x2d, 0x74, 0x34, 0xbe, 0x3e, 0x7c, 0xb9, 0x0b, 0x00, 0xf3, 0xa6, 0x74, 0x08, 0x83, 0xc3, 0x20, 0x4a, 0x75, 0xe9, 0xeb, 0xd3, 0x26, 0x66, 0x0f, 0xb7, 0x47, 0x1a, 0xba, 0x80, 0x0f, 0x8e, 0xc2, 0x31, 0xff, 0xe8, 0x24, 0x00, 0x83, 0xf8, 0xf8, 0x72, 0xf8, 0x8a, 0x16, 0x24, 0x7c, 0x8a, 0x36, 0xfd, 0x7d, 0xea, 0x00, 0xf8, 0x00, 0x00, 0xbe, 0x49, 0x7c, 0xe8, 0x7b, 0x00, 0xbe, 0x58, 0x7c, 0xe8, 0x75, 0x00, 0x31, 0xc0, 0xcd, 0x16, 0xcd, 0x19, 0x66, 0x60, 0x66, 0x48, 0x66, 0x48, 0x66, 0x0f, 0xb6, 0x8e, 0x2d, 0x00, 0x66, 0xf7, 0xe1, 0x66, 0x03, 0x46, 0x00, 0xe8, 0x18, 0x00, 0x66, 0x61, 0x06, 0xbb, 0x02, 0x00, 0xf7, 0xe3, 0xc1, 0xe2, 0x0c, 0x81, 0xc2, 0x00, 0x80, 0x8e, 0xc2, 0x89, 0xc3, 0x26, 0x8b, 0x07, 0x07, 0xc3, 0x66, 0x0f, 0xb7, 0xd9, 0x83, 0xfb, 0x40, 0x76, 0x03, 0xbb, 0x40, 0x00, 0x66, 0x60, 0x66, 0x6a, 0x00, 0x66, 0x50, 0x06, 0x57, 0x53, 0x6a, 0x10, 0x89, 0xe6, 0x8a, 0x16, 0x24, 0x7c, 0xb4, 0x42, 0xcd, 0x13, 0x72, 0x9c, 0x83, 0xc4, 0x10, 0xc1, 0xe3, 0x05, 0x8c, 0xc0, 0x01, 0xd8, 0x8e, 0xc0, 0x66, 0x61, 0x66, 0x01, 0xd8, 0x29, 0xd9, 0x75, 0xc7, 0xc3, 0xb4, 0x0e, 0xbb, 0x07, 0x00, 0xcd, 0x10, 0xac, 0x08, 0xc0, 0x75, 0xf4, 0xc3, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x55, 0xaa };
2,774
C
.h
40
67.4
72
0.666789
pbatard/rufus
28,236
2,528
13
GPL-3.0
9/7/2024, 9:40:14 AM (Europe/Amsterdam)
false
false
false
true
false
false
false
true
5,007
br_fat16_0x0.h
pbatard_rufus/src/ms-sys/inc/br_fat16_0x0.h
unsigned char br_fat16_0x0[] = { 0xeb, 0x3c, 0x90, 0x4d, 0x53, 0x57, 0x49, 0x4e, 0x34, 0x2e, 0x31 };
103
C
.h
3
32.666667
66
0.66
pbatard/rufus
28,236
2,528
13
GPL-3.0
9/7/2024, 9:40:14 AM (Europe/Amsterdam)
false
false
false
true
false
false
false
true
5,008
br_fat32_0x0.h
pbatard_rufus/src/ms-sys/inc/br_fat32_0x0.h
unsigned char br_fat32_0x0[] = { 0xeb, 0x58, 0x90, 0x4d, 0x53, 0x57, 0x49, 0x4e, 0x34, 0x2e, 0x31 };
103
C
.h
3
32.666667
66
0.66
pbatard/rufus
28,236
2,528
13
GPL-3.0
9/7/2024, 9:40:14 AM (Europe/Amsterdam)
false
false
false
true
false
false
false
true
5,010
mbr_2000.h
pbatard_rufus/src/ms-sys/inc/mbr_2000.h
/* First 446 bytes of MBR from Windows 2000, XP and 2003 */ /* This is English version. Bytes 0x12c onwards vary with language. */ /* Last three bytes 1b5-1b7 point to language-specific messages. */ /* Support of other languages is an exercise for the reader! */ /* see: http://thestarman.pcministry.com/asm/mbr/Win2kmbr.htm */ #define MBR_2000_LANG_INDEP_LEN 0x12c unsigned char mbr_2000_0x0[] = { 0x33, 0xc0, 0x8e, 0xd0, 0xbc, 0x00, 0x7c, 0xfb, 0x50, 0x07, 0x50, 0x1f, 0xfc, 0xbe, 0x1b, 0x7c, 0xbf, 0x1b, 0x06, 0x50, 0x57, 0xb9, 0xe5, 0x01, 0xf3, 0xa4, 0xcb, 0xbd, 0xbe, 0x07, 0xb1, 0x04, 0x38, 0x6e, 0x00, 0x7c, 0x09, 0x75, 0x13, 0x83, 0xc5, 0x10, 0xe2, 0xf4, 0xcd, 0x18, 0x8b, 0xf5, 0x83, 0xc6, 0x10, 0x49, 0x74, 0x19, 0x38, 0x2c, 0x74, 0xf6, 0xa0, 0xb5, 0x07, 0xb4, 0x07, 0x8b, 0xf0, 0xac, 0x3c, 0x00, 0x74, 0xfc, 0xbb, 0x07, 0x00, 0xb4, 0x0e, 0xcd, 0x10, 0xeb, 0xf2, 0x88, 0x4e, 0x10, 0xe8, 0x46, 0x00, 0x73, 0x2a, 0xfe, 0x46, 0x10, 0x80, 0x7e, 0x04, 0x0b, 0x74, 0x0b, 0x80, 0x7e, 0x04, 0x0c, 0x74, 0x05, 0xa0, 0xb6, 0x07, 0x75, 0xd2, 0x80, 0x46, 0x02, 0x06, 0x83, 0x46, 0x08, 0x06, 0x83, 0x56, 0x0a, 0x00, 0xe8, 0x21, 0x00, 0x73, 0x05, 0xa0, 0xb6, 0x07, 0xeb, 0xbc, 0x81, 0x3e, 0xfe, 0x7d, 0x55, 0xaa, 0x74, 0x0b, 0x80, 0x7e, 0x10, 0x00, 0x74, 0xc8, 0xa0, 0xb7, 0x07, 0xeb, 0xa9, 0x8b, 0xfc, 0x1e, 0x57, 0x8b, 0xf5, 0xcb, 0xbf, 0x05, 0x00, 0x8a, 0x56, 0x00, 0xb4, 0x08, 0xcd, 0x13, 0x72, 0x23, 0x8a, 0xc1, 0x24, 0x3f, 0x98, 0x8a, 0xde, 0x8a, 0xfc, 0x43, 0xf7, 0xe3, 0x8b, 0xd1, 0x86, 0xd6, 0xb1, 0x06, 0xd2, 0xee, 0x42, 0xf7, 0xe2, 0x39, 0x56, 0x0a, 0x77, 0x23, 0x72, 0x05, 0x39, 0x46, 0x08, 0x73, 0x1c, 0xb8, 0x01, 0x02, 0xbb, 0x00, 0x7c, 0x8b, 0x4e, 0x02, 0x8b, 0x56, 0x00, 0xcd, 0x13, 0x73, 0x51, 0x4f, 0x74, 0x4e, 0x32, 0xe4, 0x8a, 0x56, 0x00, 0xcd, 0x13, 0xeb, 0xe4, 0x8a, 0x56, 0x00, 0x60, 0xbb, 0xaa, 0x55, 0xb4, 0x41, 0xcd, 0x13, 0x72, 0x36, 0x81, 0xfb, 0x55, 0xaa, 0x75, 0x30, 0xf6, 0xc1, 0x01, 0x74, 0x2b, 0x61, 0x60, 0x6a, 0x00, 0x6a, 0x00, 0xff, 0x76, 0x0a, 0xff, 0x76, 0x08, 0x6a, 0x00, 0x68, 0x00, 0x7c, 0x6a, 0x01, 0x6a, 0x10, 0xb4, 0x42, 0x8b, 0xf4, 0xcd, 0x13, 0x61, 0x61, 0x73, 0x0e, 0x4f, 0x74, 0x0b, 0x32, 0xe4, 0x8a, 0x56, 0x00, 0xcd, 0x13, 0xeb, 0xd6, 0x61, 0xf9, 0xc3, 0x49, 0x6e, 0x76, 0x61, 0x6c, 0x69, 0x64, 0x20, 0x70, 0x61, 0x72, 0x74, 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x74, 0x61, 0x62, 0x6c, 0x65, 0x00, 0x45, 0x72, 0x72, 0x6f, 0x72, 0x20, 0x6c, 0x6f, 0x61, 0x64, 0x69, 0x6e, 0x67, 0x20, 0x6f, 0x70, 0x65, 0x72, 0x61, 0x74, 0x69, 0x6e, 0x67, 0x20, 0x73, 0x79, 0x73, 0x74, 0x65, 0x6d, 0x00, 0x4d, 0x69, 0x73, 0x73, 0x69, 0x6e, 0x67, 0x20, 0x6f, 0x70, 0x65, 0x72, 0x61, 0x74, 0x69, 0x6e, 0x67, 0x20, 0x73, 0x79, 0x73, 0x74, 0x65, 0x6d, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x2c, 0x44, 0x63 }; /* Next four bytes used for Windows Disk Signature / Drive serial number */ /* unsigned char mbr_2000_0x1b8[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; */
3,338
C
.h
52
60.769231
75
0.656421
pbatard/rufus
28,236
2,528
13
GPL-3.0
9/7/2024, 9:40:14 AM (Europe/Amsterdam)
false
false
false
true
false
false
false
true
5,017
libbb.h
pbatard_rufus/src/bled/libbb.h
/* * Library header for busybox/Bled * * Rewritten for Bled (Base Library for Easy Decompression) * Copyright © 2014-2023 Pete Batard <[email protected]> * * Licensed under GPLv2 or later, see file LICENSE in this source tree. */ /* Memory leaks detection - define _CRTDBG_MAP_ALLOC as preprocessor macro */ #ifdef _CRTDBG_MAP_ALLOC #include <stdlib.h> #include <crtdbg.h> #endif #ifndef LIBBB_H #define LIBBB_H 1 #ifndef _WIN32 #error Only Windows platforms are supported #endif #include "platform.h" #include "msapi_utf8.h" #include <assert.h> #include <ctype.h> #include <errno.h> #include <fcntl.h> #include <inttypes.h> #include <setjmp.h> #include <stdio.h> #include <stdlib.h> #include <stdarg.h> #include <stddef.h> #include <string.h> #include <time.h> #include <direct.h> #include <sys/stat.h> #include <sys/types.h> #include <io.h> #define ONE_TB 1099511627776ULL #define ENABLE_DESKTOP 1 #if ENABLE_DESKTOP #define IF_DESKTOP(x) x #define IF_NOT_DESKTOP(x) #else #define IF_DESKTOP(x) #define IF_NOT_DESKTOP(x) x #endif #define IF_NOT_FEATURE_LZMA_FAST(x) x #define ENABLE_FEATURE_UNZIP_CDF 1 #define ENABLE_FEATURE_UNZIP_BZIP2 1 #define ENABLE_FEATURE_UNZIP_LZMA 1 #define ENABLE_FEATURE_UNZIP_XZ 1 #define uoff_t unsigned off_t #define OFF_FMT "ll" #ifndef _MODE_T_ #define _MODE_T_ typedef unsigned short mode_t; #endif #ifndef _PID_T_ #define _PID_T_ typedef int pid_t; #endif #ifndef _GID_T_ #define _GID_T_ typedef unsigned int gid_t; #endif #ifndef _UID_T_ #define _UID_T_ typedef unsigned int uid_t; #endif #ifndef MIN #define MIN(a, b) (((a) < (b)) ? (a) : (b)) #endif #ifndef MAX #define MAX(a, b) (((a) > (b)) ? (a) : (b)) #endif #ifndef PATH_MAX #define PATH_MAX MAX_PATH #endif #define BUILD_BUG_ON(condition) ((void)sizeof(char[1 - 2*!!(condition)])) #ifndef get_le64 #define get_le64(ptr) (*(const uint64_t *)(ptr)) #endif #ifndef get_le32 #define get_le32(ptr) (*(const uint32_t *)(ptr)) #endif #ifndef get_le16 #define get_le16(ptr) (*(const uint16_t *)(ptr)) #endif extern uint32_t BB_BUFSIZE; extern smallint bb_got_signal; extern uint32_t *global_crc32_table; extern jmp_buf bb_error_jmp; extern char* bb_virtual_buf; extern size_t bb_virtual_len, bb_virtual_pos; extern int bb_virtual_fd; uint32_t* crc32_filltable(uint32_t *crc_table, int endian); uint32_t crc32_le(uint32_t crc, unsigned char const *p, size_t len, uint32_t *crc32table_le); uint32_t crc32_be(uint32_t crc, unsigned char const *p, size_t len, uint32_t *crc32table_be); #define crc32_block_endian0 crc32_le #define crc32_block_endian1 crc32_be #if defined(_MSC_VER) #if _FILE_OFFSET_BITS == 64 #define stat _stat32i64 #define lseek _lseeki64 #else #define stat _stat32 #define lseek _lseek #endif #endif typedef struct _llist_t { struct _llist_t *link; char *data; } llist_t; struct timeval64 { int64_t tv_sec; int32_t tv_usec; }; extern void (*bled_printf) (const char* format, ...); extern void (*bled_progress) (const uint64_t processed_bytes); extern void (*bled_switch) (const char* filename, const uint64_t filesize); extern int (*bled_read)(int fd, void* buf, unsigned int count); extern int (*bled_write)(int fd, const void* buf, unsigned int count); extern unsigned long* bled_cancel_request; #define xfunc_die() longjmp(bb_error_jmp, 1) #define bb_printf(...) do { if (bled_printf != NULL) bled_printf(__VA_ARGS__); \ else { printf(__VA_ARGS__); putchar('\n'); } } while(0) #define bb_error_msg(...) bb_printf("\nError: " __VA_ARGS__) #define bb_error_msg_and_die(...) do {bb_error_msg(__VA_ARGS__); xfunc_die();} while(0) #define bb_error_msg_and_err(...) do {bb_error_msg(__VA_ARGS__); goto err;} while(0) #define bb_perror_msg bb_error_msg #define bb_perror_msg_and_die bb_error_msg_and_die #define bb_simple_error_msg bb_error_msg #define bb_simple_perror_msg_and_die bb_error_msg_and_die #define bb_simple_error_msg_and_die bb_error_msg_and_die #define bb_putchar putchar static inline void *xrealloc(void *ptr, size_t size) { void *ret = realloc(ptr, size); if (!ret) free(ptr); return ret; } #define bb_msg_read_error "read error" #define bb_msg_write_error "write error" #define bb_mode_string(str, mode) "[not implemented]" #define bb_make_directory(path, mode, flags) SHCreateDirectoryExU(NULL, path, NULL) static inline int link(const char *oldpath, const char *newpath) {errno = ENOSYS; return -1;} static inline int symlink(const char *oldpath, const char *newpath) {errno = ENOSYS; return -1;} static inline int chown(const char *path, uid_t owner, gid_t group) {errno = ENOSYS; return -1;} static inline int mknod(const char *pathname, mode_t mode, dev_t dev) {errno = ENOSYS; return -1;} static inline int utimes64(const char* filename, const struct timeval64 times64[2]) { errno = ENOSYS; return -1; } static inline int fnmatch(const char *pattern, const char *string, int flags) {return PathMatchSpecA(string, pattern)?0:1;} static inline pid_t wait(int* status) { *status = 4; return -1; } #define wait_any_nohang wait /* This enables the display of a progress based on the number of bytes read */ extern uint64_t bb_total_rb; static inline int full_read(int fd, void *buf, unsigned int count) { int rb; if (fd < 0) { errno = EBADF; return -1; } if (buf == NULL) { errno = EFAULT; return -1; } /* None of our r/w buffers should be larger than BB_BUFSIZE */ if (count > BB_BUFSIZE) { errno = E2BIG; return -1; } if ((bled_cancel_request != NULL) && (*bled_cancel_request != 0)) { errno = EINTR; return -1; } if (fd == bb_virtual_fd) { if (bb_virtual_pos + count > bb_virtual_len) count = (unsigned int)(bb_virtual_len - bb_virtual_pos); memcpy(buf, &bb_virtual_buf[bb_virtual_pos], count); bb_virtual_pos += count; rb = (int)count; } else { rb = (bled_read != NULL) ? bled_read(fd, buf, count) : _read(fd, buf, count); } if (rb > 0) { bb_total_rb += rb; if (bled_progress != NULL) bled_progress(bb_total_rb); } return rb; } static inline int full_write(int fd, const void* buffer, unsigned int count) { /* None of our r/w buffers should be larger than BB_BUFSIZE */ if (count > BB_BUFSIZE) { errno = E2BIG; return -1; } return (bled_write != NULL) ? bled_write(fd, buffer, count) : _write(fd, buffer, count); } static inline void bb_copyfd_exact_size(int fd1, int fd2, off_t size) { off_t rb = 0; uint8_t* buf = NULL; if (fd1 < 0 || fd2 < 0) bb_error_msg_and_die("invalid fd"); /* Enforce a 1 TB limit to keep Coverity happy */ if (size > ONE_TB) bb_error_msg_and_die("too large"); buf = malloc(BB_BUFSIZE); if (buf == NULL) bb_error_msg_and_die("out of memory"); while (rb < size) { int r, w; r = full_read(fd1, buf, (unsigned int)MIN(size - rb, BB_BUFSIZE)); if (r < 0) { free(buf); bb_error_msg_and_die("read error"); } if (r == 0) { bb_error_msg("short read"); break; } w = full_write(fd2, buf, r); if (w < 0) { free(buf); bb_error_msg_and_die("write error"); } if (w != r) { bb_error_msg("short write"); break; } rb += r; } free(buf); } static inline struct tm *localtime_r(const time_t *timep, struct tm *result) { if (localtime_s(result, timep) != 0) result = NULL; return result; } #define safe_read full_read #define lstat stat #define xmalloc malloc #define xzalloc(x) calloc(x, 1) #define malloc_or_warn malloc #define mkdir(x, y) _mkdirU(x) #if defined(_MSC_VER) #define _S_IFBLK 0x3000 #define S_IFMT _S_IFMT #define S_IFDIR _S_IFDIR #define S_IFCHR _S_IFCHR #define S_IFIFO _S_IFIFO #define S_IFREG _S_IFREG #define S_IREAD _S_IREAD #define S_IWRITE _S_IWRITE #define S_IEXEC _S_IEXEC #define S_IFBLK _S_IFBLK #define S_ISDIR(m) (((m) & _S_IFMT) == _S_IFDIR) #define S_ISFIFO(m) (((m) & _S_IFMT) == _S_IFIFO) #define S_ISCHR(m) (((m) & _S_IFMT) == _S_IFCHR) #define S_ISBLK(m) (((m) & _S_IFMT) == _S_IFBLK) #define S_ISREG(m) (((m) & _S_IFMT) == _S_IFREG) #define O_RDONLY _O_RDONLY #define O_WRONLY _O_WRONLY #define O_RDWR _O_RDWR #define O_APPEND _O_APPEND #define O_CREAT _O_CREAT #define O_TRUNC _O_TRUNC #define O_EXCL _O_EXCL #endif /* MinGW doesn't know these */ #define _S_IFLNK 0xA000 #define _S_IFSOCK 0xC000 #define S_IFLNK _S_IFLNK #define S_IFSOCK _S_IFSOCK #define S_ISLNK(m) (((m) & _S_IFMT) == _S_IFLNK) #define S_ISSOCK(m) (((m) & _S_IFMT) == _S_IFSOCK) #endif
8,448
C
.h
277
28.801444
123
0.689893
pbatard/rufus
28,236
2,528
13
GPL-3.0
9/7/2024, 9:40:14 AM (Europe/Amsterdam)
false
false
false
false
false
false
false
true
5,018
bled.h
pbatard_rufus/src/bled/bled.h
/* * Bled (Base Library for Easy Decompression) * * Copyright © 2014-2015 Pete Batard <[email protected]> * * Licensed under GPLv2 or later, see file LICENSE in this source tree. */ #include <windows.h> #include <stdint.h> #pragma once #ifndef ARRAYSIZE #define ARRAYSIZE(A) (sizeof(A)/sizeof((A)[0])) #endif typedef void (*printf_t) (const char* format, ...); typedef void (*progress_t) (const uint64_t read_bytes); typedef int (*read_t)(int fd, void* buf, unsigned int count); typedef int (*write_t)(int fd, const void* buf, unsigned int count); typedef void (*switch_t)(const char* filename, const uint64_t size); typedef enum { BLED_COMPRESSION_NONE = 0, BLED_COMPRESSION_ZIP, // .zip BLED_COMPRESSION_LZW, // .Z BLED_COMPRESSION_GZIP, // .gz BLED_COMPRESSION_LZMA, // .lzma BLED_COMPRESSION_BZIP2, // .bz2 BLED_COMPRESSION_XZ, // .xz BLED_COMPRESSION_7ZIP, // .7z BLED_COMPRESSION_VTSI, // .vtsi BLED_COMPRESSION_MAX } bled_compression_type; /* Uncompress file 'src', compressed using 'type', to file 'dst' */ int64_t bled_uncompress(const char* src, const char* dst, int type); /* Uncompress using Windows handles */ int64_t bled_uncompress_with_handles(HANDLE hSrc, HANDLE hDst, int type); /* Uncompress file 'src', compressed using 'type', to buffer 'buf' of size 'size' */ int64_t bled_uncompress_to_buffer(const char* src, char* buf, size_t size, int type); /* Uncompress all files from archive 'src', compressed using 'type', to destination dir 'dir' */ int64_t bled_uncompress_to_dir(const char* src, const char* dir, int type); /* Uncompress buffer 'src' of length 'src_len' to buffer 'dst' of size 'dst_len' */ int64_t bled_uncompress_from_buffer_to_buffer(const char* src, const size_t src_len, char* dst, size_t dst_len, int type); /* Initialize the library. * When the parameters are not NULL or zero you can: * - specify the buffer size to use (must be larger than 64KB and a power of two) * - specify the printf-like function you want to use to output message * void print_function(const char* format, ...); * - specify the read/write functions you want to use; * - specify the function you want to use to display progress, based on number of source archive bytes read * void progress_function(const uint64_t read_bytes); * - specify the function you want to use when switching files in an archive * void switch_function(const char* filename, const uint64_t filesize); * - point to an unsigned long variable, to be used to cancel operations when set to non zero */ int bled_init(uint32_t buffer_size, printf_t print_function, read_t read_function, write_t write_function, progress_t progress_function, switch_t switch_function, unsigned long* cancel_request); /* This call frees any resource used by the library */ void bled_exit(void);
2,809
C
.h
56
48.392857
122
0.735133
pbatard/rufus
28,236
2,528
13
GPL-3.0
9/7/2024, 9:40:14 AM (Europe/Amsterdam)
false
false
false
false
false
false
false
true
5,021
unistd.h
pbatard_rufus/src/msvc-missing/unistd.h
/** * This file has no copyright assigned and is placed in the Public Domain. * This file was originally part of the w64 mingw-runtime package. */ /* Workaround unistd.h for MS compilers */ #ifndef _MSC_VER #error This header should only be used with Microsoft compilers #endif #include <windows.h> #ifndef _UNISTD_H_ #define _UNISTD_H_ /* mode_t is used in the libcdio headers */ #ifndef _MODE_T_DEFINED #define _MODE_T_DEFINED typedef unsigned short mode_t; #endif /* _MODE_T_DEFINED */ /* ssize_t is also not available (copy/paste from MinGW) */ #ifndef _SSIZE_T_DEFINED #define _SSIZE_T_DEFINED #undef ssize_t #ifdef _WIN64 typedef __int64 ssize_t; #else typedef int ssize_t; #endif /* _WIN64 */ #endif /* _SSIZE_T_DEFINED */ /* ext2fs needs this, which we picked from libcdio-driver/filemode.h */ #if !defined S_IFBLK && defined _WIN32 # define S_IFBLK 0x3000 #endif #if !defined S_ISBLK && defined S_IFBLK # define S_ISBLK(m) (((m) & S_IFMT) == S_IFBLK) #endif #endif
985
C
.h
34
27.647059
74
0.735949
pbatard/rufus
28,236
2,528
13
GPL-3.0
9/7/2024, 9:40:14 AM (Europe/Amsterdam)
false
false
false
true
false
false
false
true
5,053
ep_generate_release_name.c
valinet_ExplorerPatcher/ep_generate_release_name/ep_generate_release_name.c
#include "../ExplorerPatcher/queryversion.h" int main(int argc, char** argv) { SetConsoleOutputCP(CP_UTF8); DWORD dwLeftMost = 0; DWORD dwSecondLeft = 0; DWORD dwSecondRight = 0; DWORD dwRightMost = 0; QueryVersionInfo(GetModuleHandle(NULL), VS_VERSION_INFO, &dwLeftMost, &dwSecondLeft, &dwSecondRight, &dwRightMost); printf("%d.%d.%d.%d", dwLeftMost, dwSecondLeft, dwSecondRight, dwRightMost); return 0; }
459
C
.c
12
32.916667
120
0.703196
valinet/ExplorerPatcher
23,702
1,028
201
GPL-2.0
9/7/2024, 9:40:14 AM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
5,067
fmemopen.c
valinet_ExplorerPatcher/ExplorerPatcher/fmemopen.c
/* * Copyright (c) 2017 Joachim Nilsson <[email protected]> * * Permission to use, copy, modify, and/or distribute this software for any * purpose with or without fee is hereby granted, provided that the above * copyright notice and this permission notice appear in all copies. * * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ #include "fmemopen.h" FILE* fmemopen(void* buf, size_t len, const char* type) { int fd; FILE* fp; char tp[MAX_PATH - 13]; char fn[MAX_PATH + 1]; if (!GetTempPathA(sizeof(tp), tp)) return NULL; if (!GetTempFileNameA(tp, "eptmp", 0, fn)) return NULL; _sopen_s(&fd, fn, _O_CREAT | _O_RDWR | _O_SHORT_LIVED | _O_TEMPORARY | _O_BINARY, _SH_DENYRW, _S_IREAD | _S_IWRITE); if (fd == -1) return NULL; fp = _fdopen(fd, "w+"); if (!fp) { _close(fd); return NULL; } fwrite(buf, len, 1, fp); rewind(fp); return fp; }
1,390
C
.c
41
30.487805
76
0.696402
valinet/ExplorerPatcher
23,702
1,028
201
GPL-2.0
9/7/2024, 9:40:14 AM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
5,075
resource.h
valinet_ExplorerPatcher/ExplorerPatcher/resource.h
//{{NO_DEPENDENCIES}} // Microsoft Visual C++ generated include file. // Used by ExplorerPatcher.rc // #define IDS_PRODUCTNAME 102 #define IDS_INSTALL_SUCCESS_TEXT 109 #define IDS_INSTALL_ERROR_TEXT 110 #define IDS_UNINSTALL_SUCCESS_TEXT 111 #define IDS_UNINSTALL_ERROR_TEXT 112 #define IDS_OPERATION_NONE 113 #define IDR_REFRESHEDSTYLES_XBF 115 #define IDS_DRIVECATEGORY_HARDDISKDRIVES 40000 #define IDS_DRIVECATEGORY_REMOVABLESTORAGE 40001 #define IDS_DRIVECATEGORY_OTHER 40002 #define IDS_DRIVECATEGORY_IMAGING 40003 #define IDS_DRIVECATEGORY_PORTABLEMEDIA 40004 #define IDS_DRIVECATEGORY_PORTABLEMEDIADEVICE 40004 #define IDS_DRIVECATEGORY_PORTABLEDEVICE 40005 // Next default values for new objects // #ifdef APSTUDIO_INVOKED #ifndef APSTUDIO_READONLY_SYMBOLS #define _APS_NEXT_RESOURCE_VALUE 111 #define _APS_NEXT_COMMAND_VALUE 40001 #define _APS_NEXT_CONTROL_VALUE 1001 #define _APS_NEXT_SYMED_VALUE 101 #endif #endif
1,155
C
.c
28
39.142857
60
0.667556
valinet/ExplorerPatcher
23,702
1,028
201
GPL-2.0
9/7/2024, 9:40:14 AM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
5,081
ImmersiveFlyouts.c
valinet_ExplorerPatcher/ExplorerPatcher/ImmersiveFlyouts.c
#include "ImmersiveFlyouts.h" void InvokeActionCenter() { HRESULT hr = S_OK; IUnknown* pImmersiveShell = NULL; hr = CoCreateInstance( &CLSID_ImmersiveShell, NULL, CLSCTX_NO_CODE_DOWNLOAD | CLSCTX_LOCAL_SERVER, &IID_IServiceProvider, &pImmersiveShell ); if (SUCCEEDED(hr)) { IShellExperienceManagerFactory* pShellExperienceManagerFactory = NULL; IUnknown_QueryService( pImmersiveShell, &CLSID_ShellExperienceManagerFactory, &CLSID_ShellExperienceManagerFactory, &pShellExperienceManagerFactory ); if (pShellExperienceManagerFactory) { HSTRING_HEADER hstringHeader; HSTRING hstring = NULL; hr = WindowsCreateStringReference( L"Windows.Internal.ShellExperience.ControlCenter", (UINT32)(sizeof(L"Windows.Internal.ShellExperience.ControlCenter") / sizeof(wchar_t) - 1), &hstringHeader, &hstring ); if (hstring) { IUnknown* pIntf = NULL; pShellExperienceManagerFactory->lpVtbl->GetExperienceManager( pShellExperienceManagerFactory, hstring, &pIntf ); if (pIntf) { IActionCenterOrControlCenterExperienceManager* pControlCenterExperienceManager = NULL; pIntf->lpVtbl->QueryInterface(pIntf, &IID_ControlCenterExperienceManager, &pControlCenterExperienceManager); if (pControlCenterExperienceManager) { pControlCenterExperienceManager->lpVtbl->HotKeyInvoked(pControlCenterExperienceManager, 0); pControlCenterExperienceManager->lpVtbl->Release(pControlCenterExperienceManager); } } WindowsDeleteString(hstring); } pShellExperienceManagerFactory->lpVtbl->Release(pShellExperienceManagerFactory); } pImmersiveShell->lpVtbl->Release(pImmersiveShell); } } HRESULT InvokeFlyoutRect(BOOL bAction, DWORD dwWhich, __x_ABI_CWindows_CFoundation_CRect* pRc) { HRESULT hr = S_OK; IUnknown* pImmersiveShell = NULL; hr = CoCreateInstance( &CLSID_ImmersiveShell, NULL, CLSCTX_NO_CODE_DOWNLOAD | CLSCTX_LOCAL_SERVER, &IID_IServiceProvider, &pImmersiveShell ); if (SUCCEEDED(hr)) { IShellExperienceManagerFactory* pShellExperienceManagerFactory = NULL; hr = IUnknown_QueryService( pImmersiveShell, &CLSID_ShellExperienceManagerFactory, &CLSID_ShellExperienceManagerFactory, &pShellExperienceManagerFactory ); if (SUCCEEDED(hr)) { HSTRING_HEADER hstringHeader; HSTRING hstring = NULL; WCHAR* pwszStr = NULL; switch (dwWhich) { case INVOKE_FLYOUT_NETWORK: pwszStr = L"Windows.Internal.ShellExperience.NetworkFlyout"; break; case INVOKE_FLYOUT_CLOCK: pwszStr = L"Windows.Internal.ShellExperience.TrayClockFlyout"; break; case INVOKE_FLYOUT_BATTERY: pwszStr = L"Windows.Internal.ShellExperience.TrayBatteryFlyout"; break; case INVOKE_FLYOUT_SOUND: pwszStr = L"Windows.Internal.ShellExperience.MtcUvc"; break; } hr = WindowsCreateStringReference( pwszStr, pwszStr ? wcslen(pwszStr) : 0, &hstringHeader, &hstring ); if (SUCCEEDED(hr)) { IUnknown* pIntf = NULL; hr = pShellExperienceManagerFactory->lpVtbl->GetExperienceManager( pShellExperienceManagerFactory, hstring, &pIntf ); if (SUCCEEDED(hr)) { IExperienceManager* pExperienceManager = NULL; hr = pIntf->lpVtbl->QueryInterface( pIntf, dwWhich == INVOKE_FLYOUT_NETWORK ? &IID_NetworkFlyoutExperienceManager : (dwWhich == INVOKE_FLYOUT_CLOCK ? &IID_TrayClockFlyoutExperienceManager : (dwWhich == INVOKE_FLYOUT_BATTERY ? &IID_TrayBatteryFlyoutExperienceManager : (dwWhich == INVOKE_FLYOUT_SOUND ? &IID_TrayMtcUvcFlyoutExperienceManager : &IID_IUnknown))), &pExperienceManager ); if (SUCCEEDED(hr)) { if (bAction == INVOKE_FLYOUT_SHOW) { hr = pExperienceManager->lpVtbl->ShowFlyout(pExperienceManager, pRc); } else if (bAction == INVOKE_FLYOUT_HIDE) { hr = pExperienceManager->lpVtbl->HideFlyout(pExperienceManager); } pExperienceManager->lpVtbl->Release(pExperienceManager); } } WindowsDeleteString(hstring); } pShellExperienceManagerFactory->lpVtbl->Release(pShellExperienceManagerFactory); } pImmersiveShell->lpVtbl->Release(pImmersiveShell); } return hr; }
5,811
C
.c
142
25.612676
129
0.54035
valinet/ExplorerPatcher
23,702
1,028
201
GPL-2.0
9/7/2024, 9:40:14 AM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
5,102
EPSettingsResources.h
valinet_ExplorerPatcher/ep_gui/resources/EPSettingsResources.h
#pragma once // 1001 - 2200 #define IDS_TB 1001 #define IDS_TB_STYLE 1002 #define IDS_TB_STYLE_0 1003 #define IDS_TB_STYLE_1 1004 #define IDS_TB_MORE 1005 #define IDS_TB_CUSTOMIZETRAYICONS 1006 #define IDS_TB_CUSTOMIZESYSTEMICONS 1007 #define IDS_TB_PRIMARYTBPOS 1008 #define IDS_TB_POSBOTTOM 1009 #define IDS_TB_POSTOP 1010 #define IDS_TB_POSLEFT 1011 #define IDS_TB_POSRIGHT 1012 #define IDS_TB_SECONDARYTBPOS 1013 #define IDS_TB_EXTRABTN 1014 #define IDS_TB_EXTRABTN_0 1015 #define IDS_TB_EXTRABTN_2 1016 #define IDS_TB_EXTRABTN_1 1017 #define IDS_TB_SEARCHMODE_W11 1018 #define IDS_TB_SEARCHMODE 1019 #define IDS_TB_SEARCHMODE_0 1020 #define IDS_TB_SEARCHMODE_1 1021 #define IDS_TB_SEARCHMODE_2 1022 #define IDS_TB_CORTANABTN 1023 #define IDS_TB_TASKVIEWBTN 1024 #define IDS_TB_WIDGETSBTN 1025 #define IDS_TB_AUTOHIDETB 1026 #define IDS_TB_STARTBTNSTYLE 1027 #define IDS_TB_STARTBTNSTYLE_0 1028 #define IDS_TB_STARTBTNSTYLE_1 1029 #define IDS_TB_PRIMARYTBALIGN 1030 #define IDS_TB_TBALIGN_0 1031 #define IDS_TB_TBALIGN_1 1032 #define IDS_TB_TBALIGN_5 1033 #define IDS_TB_TBALIGN_3 1034 #define IDS_TB_TBALIGN_7 1035 #define IDS_TB_SECONDARYTBALIGN 1036 #define IDS_TB_PRIMARYTBGLOM 1037 #define IDS_TB_GLOM_0_D 1038 #define IDS_TB_GLOM_0 1039 #define IDS_TB_GLOM_1 1040 #define IDS_TB_GLOM_2 1042 #define IDS_TB_SECONDARYTBGLOM 1043 #define IDS_TB_ICONSIZE 1044 #define IDS_TB_ICONSIZE_1 1045 #define IDS_TB_ICONSIZE_0 1046 #define IDS_TB_STYLE_2 1047 #define IDS_TB_ALTIMPL_NOTICE 1048 #define IDS_TB_WIN10_UNAVAILABLE 1049 #define IDS_TRAY 1101 #define IDS_TRAY_SKINMENUS 1102 #define IDS_TRAY_CENTERMENUS 1103 #define IDS_TRAY_FLYOUTMENUS 1104 #define IDS_TRAY_TOUCHKB 1105 #define IDS_TRAY_SHOWSECONDS 1106 #define IDS_TRAY_CCBTN 1107 #define IDS_TRAY_SHOWDESKTOPBTN 1108 #define IDS_TRAY_SHOWDESKTOPBTN_1 1109 #define IDS_TRAY_SHOWDESKTOPBTN_0 1110 #define IDS_TRAY_SHOWDESKTOPBTN_2 1111 #define IDS_TRAY_SKINICONS 1112 #define IDS_TRAY_REPLACENETWORK_L1 1113 #define IDS_TRAY_REPLACENETWORK_L2 1114 #define IDS_TRAY_REPLACENETWORK_0 1115 #define IDS_TRAY_REPLACENETWORK_1 1116 #define IDS_TRAY_REPLACENETWORK_2 1117 #define IDS_TRAY_SYSICONBEHAVIOR 1118 #define IDS_TRAY_NETWORK 1119 #define IDS_TRAY_NETWORK_6 1120 #define IDS_TRAY_NETWORK_5 1121 #define IDS_TRAY_NETWORK_0 1122 #define IDS_TRAY_NETWORK_2 1123 #define IDS_TRAY_NETWORK_1 1124 #define IDS_TRAY_SOUND 1125 #define IDS_TRAY_SOUND_1 1126 #define IDS_TRAY_SOUND_0 1127 #define IDS_TRAY_CLOCK 1128 #define IDS_TRAY_CLOCK_2 1129 #define IDS_TRAY_CLOCK_0 1130 #define IDS_TRAY_CLOCK_1 1131 #define IDS_TRAY_CLOCK_2_W10 1132 #define IDS_TRAY_BATTERY 1133 #define IDS_TRAY_BATTERY_0 1134 #define IDS_TRAY_BATTERY_1 1135 #define IDS_TRAY_LANGSWITCHER 1136 #define IDS_TRAY_LANGSWITCHER_0 1137 #define IDS_TRAY_LANGSWITCHER_1_21H2 1138 #define IDS_TRAY_LANGSWITCHER_7 1140 #define IDS_TRAY_LANGSWITCHER_1 1141 #define IDS_TRAY_LANGSWITCHER_4 1142 #define IDS_TRAY_OVERFLOWSTYLE 1143 #define IDS_TRAY_OVERFLOWSTYLE_0 1144 #define IDS_TRAY_OVERFLOWSTYLE_1 1145 #define IDS_EXP 1201 #define IDS_EXP_SHEXT_L1 1202 #define IDS_EXP_SHEXT_L2 1203 #define IDS_EXP_SHEXT_LEARN 1204 #define IDS_EXP_SHEXT_REGISTER 1205 #define IDS_EXP_DISABLECTXMENU 1206 #define IDS_EXP_LEGACYFTDIALOG 1207 #define IDS_EXP_CLASSICDRIVEGROUP 1208 #define IDS_EXP_CTRLINTF 1209 #define IDS_EXP_CTRLINTF_0_W11 1210 #define IDS_EXP_CTRLINTF_3 1211 #define IDS_EXP_CTRLINTF_4 1212 #define IDS_EXP_CTRLINTF_0_W10 1213 #define IDS_EXP_CTRLINTF_1_W11 1214 #define IDS_EXP_CTRLINTF_2 1215 #define IDS_EXP_NEWWINDOWS 1216 #define IDS_EXP_IMMERSIVEMENUS 1217 #define IDS_EXP_DISABLENAVBAR 1218 #define IDS_EXP_DISABLESEARCHBAR 1219 #define IDS_EXP_SHRINKADDRESSBAR 1220 #define IDS_EXP_HIDESEARCHBAR 1221 #define IDS_EXP_TITLEBAR 1222 #define IDS_EXP_TITLEBAR_0 1223 #define IDS_EXP_TITLEBAR_1 1224 #define IDS_EXP_TITLEBAR_2 1225 #define IDS_EXP_TITLEBAR_3 1226 #define IDS_EXP_MICA 1227 #define IDS_START 1301 #define IDS_START_STYLE 1302 #define IDS_START_STYLE_0 1303 #define IDS_START_STYLE_1 1304 #define IDS_START_MORE 1305 #define IDS_START_POSITION 1306 #define IDS_START_POSITION_0 1307 #define IDS_START_POSITION_1 1308 #define IDS_START_MAXFREQAPPS 1309 #define IDS_START_MAXFREQAPPS_0 1310 #define IDS_START_MAXFREQAPPS_6 1311 #define IDS_START_MAXFREQAPPS_99999 1312 #define IDS_START_MONITOROVERRIDE_L1 1313 #define IDS_START_MONITOROVERRIDE_L2 1314 #define IDS_START_MONITOROVERRIDE_1 1315 #define IDS_START_MONITOROVERRIDE_0 1316 #define IDS_START_MONITOROVERRIDE_2 1317 #define IDS_START_MONITOROVERRIDE_3 1318 #define IDS_START_MONITOROVERRIDE_4 1319 #define IDS_START_MONITOROVERRIDE_5 1320 #define IDS_START_MONITOROVERRIDE_6 1321 #define IDS_START_MONITOROVERRIDE_7 1322 #define IDS_START_MONITOROVERRIDE_8 1323 #define IDS_START_MONITOROVERRIDE_9 1324 #define IDS_START_NORECOMMENDED 1325 #define IDS_START_MAKEALLAPPSDEFAULT 1326 #define IDS_START_SHOWMORETILES 1327 #define IDS_START_CORNERPREF 1328 #define IDS_START_CORNERPREF_1 1329 #define IDS_START_CORNERPREF_2 1330 #define IDS_START_CORNERPREF_0 1331 #define IDS_START_DISPLAYMODE 1332 #define IDS_START_DISPLAYMODE_0 1333 #define IDS_START_DISPLAYMODE_1 1334 #define IDS_START_DISPLAYMODE_2 1335 #define IDS_START_APPLIST 1336 #define IDS_START_APPLIST_0 1337 #define IDS_START_APPLIST_3 1338 #define IDS_START_APPLIST_1 1339 #define IDS_START_NOTICE 1340 #define IDS_START_WIN10_NOTICE 1341 #define IDS_AT 1401 #define IDS_AT_STYLE 1402 #define IDS_AT_STYLE_0_W11 1403 #define IDS_AT_STYLE_0_W10 1404 #define IDS_AT_STYLE_3 1405 #define IDS_AT_STYLE_1 1406 #define IDS_AT_STYLE_2 1407 #define IDS_AT_SWS_INCLUDEWALLPAPER 1408 #define IDS_AT_SWS_PRIMARYONLY 1409 #define IDS_AT_SWS_PERMONITOR 1410 #define IDS_AT_SWS_GROUPWINDOWS 1411 #define IDS_AT_SWS_NOPERAPP 1412 #define IDS_AT_SWS_THEME 1413 #define IDS_AT_SWS_THEME_0 1414 #define IDS_AT_SWS_THEME_1 1415 #define IDS_AT_SWS_THEME_2 1416 #define IDS_AT_SWS_OPACITY 1417 #define IDS_AT_SWS_OPACITY_100 1418 #define IDS_AT_SWS_OPACITY_95 1419 #define IDS_AT_SWS_COLORSCHEME 1420 #define IDS_AT_SWS_COLORSCHEME_0 1421 #define IDS_AT_SWS_COLORSCHEME_1 1422 #define IDS_AT_SWS_COLORSCHEME_2 1423 #define IDS_AT_SWS_CORNERPREF 1424 #define IDS_AT_SWS_CORNERPREF_2 1425 #define IDS_AT_SWS_CORNERPREF_3 1426 #define IDS_AT_SWS_CORNERPREF_1 1427 #define IDS_AT_SWS_ROWHEIGHT 1428 #define IDS_AT_SWS_ROWHEIGHT_230 1429 #define IDS_AT_SWS_MAXWIDTH 1430 #define IDS_AT_SWS_MAXWIDTH_100 1431 #define IDS_AT_SWS_MAXWIDTH_80 1432 #define IDS_AT_SWS_MAXHEIGHT 1433 #define IDS_AT_SWS_MAXHEIGHT_100 1434 #define IDS_AT_SWS_MAXHEIGHT_80 1435 #define IDS_AT_SWS_PADDING 1436 #define IDS_AT_SWS_PADDING_20 1437 #define IDS_AT_SWS_PADDING_0 1438 #define IDS_AT_SWS_SHOWDELAY 1439 #define IDS_AT_SWS_SHOWDELAY_0 1440 #define IDS_AT_SWS_SHOWDELAY_25 1441 #define IDS_AT_SWS_SHOWDELAY_50 1442 #define IDS_AT_SWS_SHOWDELAY_75 1443 #define IDS_AT_SWS_SHOWDELAY_100 1444 #define IDS_AT_SWS_SHOWDELAY_125 1445 #define IDS_AT_SWS_SHOWDELAY_150 1446 #define IDS_AT_SWS_SHOWDELAY_200 1447 #define IDS_AT_SWS_SHOWDELAY_300 1448 #define IDS_AT_SWS_SHOWDELAY_400 1449 #define IDS_AT_SWS_SHOWDELAY_500 1450 #define IDS_AT_SWS_SCROLLWHEEL 1451 #define IDS_AT_SWS_SCROLLWHEEL_0 1452 #define IDS_AT_SWS_SCROLLWHEEL_1 1453 #define IDS_AT_SWS_SCROLLWHEEL_2 1454 #define IDS_AT_SWS_LEARN 1455 #define IDS_WEATHER 1501 #define IDS_WEATHER_SHOW 1502 #define IDS_WEATHER_LOC 1503 #define IDS_WEATHER_LOC_PROMPT 1504 #define IDS_WEATHER_LOC_DEFAULT 1505 #define IDS_WEATHER_LAYOUT 1506 #define IDS_WEATHER_LAYOUT_0 1507 #define IDS_WEATHER_LAYOUT_3 1508 #define IDS_WEATHER_LAYOUT_1 1509 #define IDS_WEATHER_LAYOUT_4 1510 #define IDS_WEATHER_LAYOUT_5 1511 #define IDS_WEATHER_SIZE 1512 #define IDS_WEATHER_SIZE_0 1513 #define IDS_WEATHER_SIZE_2 1514 #define IDS_WEATHER_SIZE_1 1515 #define IDS_WEATHER_POSITION 1516 #define IDS_WEATHER_POSITION_0 1517 #define IDS_WEATHER_POSITION_1 1518 #define IDS_WEATHER_UPDATEFREQ 1519 #define IDS_WEATHER_UPDATEFREQ_60 1520 #define IDS_WEATHER_UPDATEFREQ_300 1521 #define IDS_WEATHER_UPDATEFREQ_900 1522 #define IDS_WEATHER_UPDATEFREQ_1200 1523 #define IDS_WEATHER_UPDATEFREQ_1800 1524 #define IDS_WEATHER_UPDATEFREQ_3600 1525 #define IDS_WEATHER_UPDATEFREQ_7200 1526 #define IDS_WEATHER_TEMPUNIT 1527 #define IDS_WEATHER_TEMPUNIT_0 1528 #define IDS_WEATHER_TEMPUNIT_1 1529 #define IDS_WEATHER_LANG 1533 #define IDS_WEATHER_LANG_PROMPT 1534 #define IDS_WEATHER_LANG_DEFAULT 1535 #define IDS_WEATHER_COLORSCHEME 1536 #define IDS_WEATHER_COLORSCHEME_0 1537 #define IDS_WEATHER_COLORSCHEME_1 1538 #define IDS_WEATHER_COLORSCHEME_2 1539 #define IDS_WEATHER_CORNERPREF 1540 #define IDS_WEATHER_CORNERPREF_2 1541 #define IDS_WEATHER_CORNERPREF_3 1542 #define IDS_WEATHER_CORNERPREF_1 1543 #define IDS_WEATHER_ICONPACK 1544 #define IDS_WEATHER_ICONPACK_0 1545 #define IDS_WEATHER_ICONPACK_1 1546 #define IDS_WEATHER_CONTENTSMODE 1547 #define IDS_WEATHER_CONTENTSMODE_0 1548 #define IDS_WEATHER_CONTENTSMODE_1 1549 #define IDS_WEATHER_ZOOM 1550 #define IDS_WEATHER_ZOOM_100 1551 #define IDS_WEATHER_LEARN 1552 #define IDS_WEATHER_LASTUPDATE 1553 #define IDS_WEATHER_UPDATE 1554 #define IDS_WEATHER_CLEAR 1555 #define IDS_WEATHER_CLEAR_PROMPT 1556 #define IDS_WEATHER_CLEAR_WAIT 1557 #define IDS_WEATHER_CLEAR_SUCCESS 1558 #define IDS_WEATHER_CLEAR_FAILED 1559 #define IDS_SP 1601 #define IDS_SP_HIDEICON 1602 #define IDS_SP_DESKTOPMENU 1603 #define IDS_SP_DESKTOPMENU_0 1604 #define IDS_SP_DESKTOPMENU_32 1605 #define IDS_SP_DESKTOPMENU_48 1606 #define IDS_SP_DESKTOPMENU_288 1607 #define IDS_SP_DESKTOPMENU_800 1608 #define IDS_SP_DESKTOPMENU_304 1609 #define IDS_SP_DESKTOPMENU_816 1610 #define IDS_SP_DESKTOPMENU_1008 1611 #define IDS_SP_UPDATEFREQ 1612 #define IDS_SP_UPDATEFREQ_0 1613 #define IDS_SP_UPDATEFREQ_60 1614 #define IDS_SP_UPDATEFREQ_300 1615 #define IDS_SP_UPDATEFREQ_900 1616 #define IDS_SP_UPDATEFREQ_1200 1617 #define IDS_SP_UPDATEFREQ_1800 1618 #define IDS_SP_UPDATEFREQ_3600 1619 #define IDS_SP_UPDATEFREQ_7200 1620 #define IDS_SP_UPDATEFREQ_21600 1621 #define IDS_SP_UPDATEFREQ_43200 1622 #define IDS_SP_UPDATEFREQ_86400 1623 #define IDS_SP_MOREOPTIONS 1624 #define IDS_OTHER 1701 #define IDS_OTHER_REMEMBERLAST 1702 #define IDS_OTHER_CLOCKFLYOUT 1703 #define IDS_OTHER_TOOLBARSEPARATORS 1704 #define IDS_OTHER_WINXPROPERTIES 1705 #define IDS_OTHER_DONTUSEPOWERSHELL 1706 #define IDS_OTHER_WINXACCELERATOR 1707 #define IDS_OTHER_DISABLEOFFICE 1708 #define IDS_OTHER_DISABLEWINF 1709 #define IDS_OTHER_DISABLERC 1710 #define IDS_OTHER_DISABLEAEROSNAP 1711 #define IDS_OTHER_SNAPASSISTSTYLE 1712 #define IDS_OTHER_SNAPASSISTSTYLE_0 1713 #define IDS_OTHER_SNAPASSISTSTYLE_3 1714 #define IDS_OTHER_PWRBTNACTION 1715 #define IDS_OTHER_PWRBTNACTION_256 1716 #define IDS_OTHER_PWRBTNACTION_1 1717 #define IDS_OTHER_PWRBTNACTION_16 1718 #define IDS_OTHER_PWRBTNACTION_64 1719 #define IDS_OTHER_PWRBTNACTION_2 1720 #define IDS_OTHER_PWRBTNACTION_4 1721 #define IDS_OTHER_NOREDIRECT 1722 #define IDS_OTHER_NOREDIRECT_SYSTEM 1723 #define IDS_OTHER_NOREDIRECT_PROGRAMS 1724 #define IDS_OTHER_NOREDIRECT_DATETIME 1725 #define IDS_OTHER_NOREDIRECT_TRAYICONS 1726 #define IDS_OTHER_LOGONLOGOFFSHUTDOWNSOUNDS 1727 #define IDS_UPDATES 1801 #define IDS_UPDATES_POLICY 1802 #define IDS_UPDATES_POLICY_1 1803 #define IDS_UPDATES_POLICY_0 1804 #define IDS_UPDATES_POLICY_2 1805 #define IDS_UPDATES_PREFER_STAGING 1806 #define IDS_UPDATES_DOWNGRADES 1807 #define IDS_UPDATES_UPDATESERVERS 1808 #define IDS_UPDATES_RELEASES 1809 #define IDS_UPDATES_RELEASES_PROMPT 1810 #define IDS_UPDATES_STAGING 1811 #define IDS_UPDATES_STAGING_PROMPT 1812 #define IDS_UPDATES_CHECK 1813 #define IDS_UPDATES_INSTALL 1814 #define IDS_UPDATES_CHANGES 1815 #define IDS_UPDATES_LEARN 1816 #define IDS_UPDATES_USELOCAL 1817 #define IDS_ADV 1901 #define IDS_ADV_DISCLAIMER 1902 #define IDS_ADV_LEARN 1903 #define IDS_ADV_CONSOLE 1904 #define IDS_ADV_MEMCHECK 1905 #define IDS_ADV_AUTOHIDE 1906 #define IDS_ADV_PAINTDESKTOPVERSION 1907 #define IDS_ADV_CLASSICTHEME 1908 #define IDS_ADV_SYSLISTVIEW32 1909 #define IDS_ADV_NOPROPERTIES 1910 #define IDS_ADV_SYMBOLS 1911 #define IDS_ADV_PINNEDITEMS 1912 #define IDS_ADV_REMOVEEXTRAGAP 1913 #define IDS_ADV_XAMLSOUNDS 1927 #define IDS_ABOUT 2001 #define IDS_ABOUT_VERSION 2002 #define IDS_ABOUT_PROJECT 2003 #define IDS_ABOUT_AUTHOR 2004 #define IDS_ABOUT_OS 2005 #define IDS_ABOUT_GITHUB 2006 #define IDS_ABOUT_WEBSITE 2007 #define IDS_ABOUT_DONATE 2009 #define IDS_ABOUT_FAQ 2010 #define IDS_ABOUT_SETTINGS 2011 #define IDS_ABOUT_IMPORT 2012 #define IDS_ABOUT_EXPORT 2013 #define IDS_ABOUT_EXPORT_SUCCESS 2014 #define IDS_ABOUT_RESET 2015 #define IDS_UNINSTALL 2101 #define IDS_UNINSTALL_UNINSTALL 2102 #define IDS_FOOTER_RESTART 2201 #define IDS_MAINTENANCE 2301
13,151
C
.c
373
33.168901
49
0.804786
valinet/ExplorerPatcher
23,702
1,028
201
GPL-2.0
9/7/2024, 9:40:14 AM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
5,103
EPSharedResources.h
valinet_ExplorerPatcher/ep_gui/resources/EPSharedResources.h
#pragma once // 301-350 #define IDS_UPDATES_CHECKING_T 301 #define IDS_UPDATES_AVAILABLE_T 302 #define IDS_UPDATES_AVAILABLE_T_U 303 #define IDS_UPDATES_AVAILABLE_B 304 #define IDS_UPDATES_ISLATEST_T 305 #define IDS_UPDATES_ISLATEST_B 306 #define IDS_UPDATES_CHECKFAILED_T 307 #define IDS_UPDATES_CHECKFAILED_B 308 #define IDS_UPDATES_DOWNLOADING_T 309 #define IDS_UPDATES_SUCCESS_T 310 #define IDS_UPDATES_DLFAILED_T 311 #define IDS_UPDATES_DLFAILED_B 312 #define IDS_UPDATES_INSTALLEDVER 313 #define IDS_UPDATES_PROMPT 314 #define IDS_UPDATES_AVAILABLE_A 315 #define IDS_UPDATES_DOWNLOADING_0 316 // 351-400 #define IDS_SYM_DL_T 351 #define IDS_SYM_DL_B 352 #define IDS_SYM_SUCCESS_T 353 #define IDS_SYM_SUCCESS_B 354 #define IDS_SYM_FAILEDSOME_T 355 #define IDS_SYM_FAILEDSOME_B 356 #define IDS_SYM_FAILEDALL_T 357 #define IDS_SYM_FAILEDALL_B 358 // 401-500 #define IDS_CRASH_TITLE 401 #define IDS_CRASH_BODY 402 #define IDS_CRASH_ONCE 403 #define IDS_CRASH_MULTIPLE 404 #define IDS_CRASH_DISMISS 405
1,052
C
.c
33
29.424242
38
0.785857
valinet/ExplorerPatcher
23,702
1,028
201
GPL-2.0
9/7/2024, 9:40:14 AM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
5,131
version.h
valinet_ExplorerPatcher/version.h
#define VER_MAJOR 22621 #define VER_MINOR 4317 #define VER_BUILD_HI 67 #define VER_BUILD_LO 1 #define VER_FLAGS VS_FF_PRERELEASE // The Binary form of the version numbers #define VER_FILE VER_MAJOR, VER_MINOR, VER_BUILD_HI, VER_BUILD_LO #define VER_PRODUCT VER_MAJOR, VER_MINOR, VER_BUILD_HI, VER_BUILD_LO #define VER_STR(arg) #arg #define STRINGIFYVER2(X) #X #define STRINGIFYVER(X) STRINGIFYVER2(X) #define VER_WITH_DOTS STRINGIFYVER(VER_MAJOR) "." STRINGIFYVER(VER_MINOR) "." STRINGIFYVER(VER_BUILD_HI) "." STRINGIFYVER(VER_BUILD_LO) // The String form of the version numbers #define VER_FILE_STRING VALUE "FileVersion", VER_WITH_DOTS #define VER_PRODUCT_STRING VALUE "ProductVersion", VER_WITH_DOTS
747
C
.h
15
47.133333
136
0.742382
valinet/ExplorerPatcher
23,702
1,028
201
GPL-2.0
9/7/2024, 9:40:14 AM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
5,137
ep_weather_utility.h
valinet_ExplorerPatcher/ep_weather_host/ep_weather_utility.h
#ifndef _H_EP_WEATHER_UTILITY_H_ #define _H_EP_WEATHER_UTILITY_H_ #include <Windows.h> #include <stdint.h> #include "../ExplorerPatcher/queryversion.h" #include "../ExplorerPatcher/osutility.h" extern void(*RefreshImmersiveColorPolicyState)(); extern void(*SetPreferredAppMode)(INT64 bAllowDark); extern void(*AllowDarkModeForWindow)(HWND hWnd, INT64 bAllowDark); extern BOOL(*ShouldAppsUseDarkMode)(); extern BOOL(*ShouldSystemUseDarkMode)(); inline BOOL IsColorSchemeChangeMessage(LPARAM lParam) { BOOL is = FALSE; if (lParam && CompareStringOrdinal(lParam, -1, L"ImmersiveColorSet", -1, TRUE) == CSTR_EQUAL) { is = TRUE; } return is; } inline BOOL IsHighContrast() { HIGHCONTRASTW highContrast; ZeroMemory(&highContrast, sizeof(HIGHCONTRASTW)); highContrast.cbSize = sizeof(highContrast); if (SystemParametersInfoW(SPI_GETHIGHCONTRAST, sizeof(highContrast), &highContrast, FALSE)) return highContrast.dwFlags & HCF_HIGHCONTRASTON; return FALSE; } #endif
1,047
C
.h
30
30.9
98
0.740119
valinet/ExplorerPatcher
23,702
1,028
201
GPL-2.0
9/7/2024, 9:40:14 AM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
5,171
def.h
valinet_ExplorerPatcher/ExplorerPatcher/def.h
#ifndef _H_DEF_H_ #define _H_DEF_H_ #define APPID L"Microsoft.Windows.Explorer" #define REGPATH "Software\\ExplorerPatcher" #define REGPATH_OLD "Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\ExplorerPatcher" #define REGPATH_STARTMENU REGPATH_OLD #define SPECIAL_FOLDER CSIDL_PROGRAM_FILES #define SPECIAL_FOLDER_LEGACY CSIDL_APPDATA #define PRODUCT_NAME "ExplorerPatcher" #define PRODUCT_PUBLISHER "VALINET Solutions SRL" #define APP_RELATIVE_PATH "\\" PRODUCT_NAME #define EP_CLSID_LITE "D17F1E1A-5919-4427-8F89-A1A8503CA3EB" #define EP_CLSID "{D17F1E1A-5919-4427-8F89-A1A8503CA3EB}" #define DOSMODE_OFFSET 78 #ifndef _M_ARM64 #define SETUP_UTILITY_NAME "ep_setup.exe" #else #define SETUP_UTILITY_NAME "ep_setup_arm64.exe" #endif #define TOAST_BUFSIZ 1536 #define SEH_REGPATH "Control Panel\\Quick Actions\\Control Center\\QuickActionsStateCapture\\ExplorerPatcher" #define EP_SETUP_HELPER_SWITCH "/CreateExplorerShellUnelevatedAfterServicing" #define EP_DWM_SERVICENAME "ep_dwm_" EP_CLSID_LITE #define EP_DWM_EVENTNAME "Global\\ep_dwm_2_" EP_CLSID_LITE #define EP_SETUP_EVENTNAME "Global\\ep_setup_" EP_CLSID_LITE #endif
1,157
C
.h
26
42.576923
110
0.79417
valinet/ExplorerPatcher
23,702
1,028
201
GPL-2.0
9/7/2024, 9:40:14 AM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
5,309
proto-tcp-telnet.c
robertdavidgraham_masscan/src/proto-tcp-telnet.c
#include "proto-tcp-telnet.h" #include "proto-banner1.h" #include "stack-tcp-api.h" #include "unusedparm.h" #include "masscan-app.h" #include "util-malloc.h" #include <ctype.h> #include <string.h> #include "util-safefunc.h" struct TelnetOptions { unsigned num; const char *text; }; /* This is a list of the options during negotiation that we might be interested in. */ struct TelnetOptions options[] = { { 0, "binary"}, /* 0x00 Binary */ { 1, "echo"}, /* 0x01 Echo */ //{ 2, "recon"}, /* 0x02 Reconnection */ { 3, "sga"}, /* 0x03 Suppress go ahead */ //{ 4, "msgsz"}, /* 0x04 Approx Message Size Negotiation */ { 5, "status"}, /* 0x05 Status */ { 6, "timing-mark"}, /* 0x06 Timing Mark */ /* 7 Remote Controlled Trans and Echo [107,JBP] 8 Output Line Width [40,JBP] 9 Output Page Size [41,JBP] 10 Output Carriage-Return Disposition [28,JBP] 11 Output Horizontal Tab Stops [32,JBP] 12 Output Horizontal Tab Disposition [31,JBP] 13 Output Formfeed Disposition [29,JBP] 14 Output Vertical Tabstops [34,JBP] 15 Output Vertical Tab Disposition [33,JBP] 16 Output Linefeed Disposition [30,JBP] 17 Extended ASCII [136,JBP] 18 Logout [25,MRC] 19 Byte Macro [35,JBP] 20 Data Entry Terminal [145,38,JBP]*/ //{21, "supdup"}, /* 0x15 SUPDUP */ {22, "supdupout"}, /* 0x16 SUPDUP Output */ {23, "sendloc"}, /* 0x17 Send Location */ {24, "term"}, /* 0x18 Terminal type */ /* 25 End of Record [103,JBP] 26 TACACS User Identification [1,BA4] 27 Output Marking [125,SXS] 28 Terminal Location Number [84,RN6] 29 Telnet 3270 Regime [116,JXR] 30 X.3 PAD [70,SL70] */ {31, "naws"}, /* 0x1f Negotiate About Window Size */ {32, "tspeed"}, /* 0x20 Terminal Speed */ {33, "rflow"}, /* 0x21 ! Remote Flow Control */ {34, "linemode"}, /* 0x22 " Linemode */ {35, "xloc"}, /* 0x23 # X Display Location */ {36, "env"}, /* 0x24 $ Environment Option [DB14]*/ {37, "auth"}, /* 0x25 % Authentication Option */ {38, "encrypt"}, /* 0x26 & Encryption Option */ {39, "new-env"}, /* 0x27 ' */ {46, "starttls"}, /* 0x2e . STARTTLS */ /* 255 Extended-Options-List [109,JBP] */ {0,0} }; #if 0 static const char * option_name_lookup(unsigned optnum) { size_t i; for (i=0; options[i].text; i++) { if (options[i].num == optnum) return options[i].text; } return 0; } #endif enum { FLAG_WILL=1, FLAG_WONT=2, FLAG_DO=4, FLAG_DONT=8, }; /*************************************************************************** ***************************************************************************/ static void telnet_parse( const struct Banner1 *banner1, void *banner1_private, struct StreamState *pstate, const unsigned char *px, size_t length, struct BannerOutput *banout, struct stack_handle_t *socket) { unsigned state = pstate->state; size_t offset; enum { TELNET_DATA, TELNET_IAC, TELNET_DO, TELNET_DONT, TELNET_WILL, TELNET_WONT, TELNET_SB, TELNET_SB_DATA, TELNET_INVALID, }; //static const char *foobar[4] = {"DO", "DONT", "WILL", "WONT"}; unsigned char nego[256] = {0}; UNUSEDPARM(banner1_private); UNUSEDPARM(banner1); UNUSEDPARM(socket); for (offset=0; offset<length; offset++) { int c = px[offset]; banout_append_char(banout, PROTO_TELNET, c); switch (state) { case 0: if (c == 0xFF) /* Telnet option code negotiation */ state = TELNET_IAC; break; case TELNET_IAC: switch (c) { case 240: /* 0xF0 SE - End of subnegotiation parameters */ state = 0; break; case 246: /* 0xF6 Are you there? - The function AYT. */ state = 0; break; case 241: /* 0xF1 NOP - No operation. */ state = 0; break; case 242: /* 0xF2 Data mark */ state = 0; break; case 243: /* 0xF3 BRK - NVT character BRK. */ state = 0; break; case 244: /* 0xF4 Interrupt process - The function IP. */ state = 0; break; case 245: /* 0xF5 Abort - The function AO. */ state = 0; break; case 247: /* 0xF7 Erase character - The function EC. */ state = 0; break; case 248: /* 0xF8 Erase line - The function EL. */ state = 0; break; case 249: /* 0xF9 Go ahead - The GA signal. */ state = 0; break; case 250: /* 0xFA SB - Start of subnegotiation */ state = TELNET_SB; break; case 251: /* 0xFB WILL */ state = TELNET_WILL; break; case 252: /* 0xFC WONT */ state = TELNET_WONT; break; case 253: /* 0xFD DO */ state = TELNET_DO; break; case 254: /* 0xFE DONT */ state = TELNET_DONT; break; default: case 255: /* 0xFF IAC */ /* ??? */ state = TELNET_INVALID; break; } break; case TELNET_SB_DATA: if (c == 0xFF) state = TELNET_IAC; break; case TELNET_SB: state = TELNET_SB_DATA; break; case TELNET_DO: case TELNET_DONT: case TELNET_WILL: case TELNET_WONT: switch (state) { case TELNET_DO: nego[c] = FLAG_WONT; break; case TELNET_DONT: nego[c] = FLAG_WONT; break; case TELNET_WILL: nego[c] = FLAG_DONT; break; case TELNET_WONT: nego[c] = FLAG_DONT; break; } state = 0; break; default: offset = (unsigned)length; break; } } { #define r_length (256*3*4) unsigned char reply[r_length]; size_t r_offset = 0; size_t i; for (i=0; i<256 && r_offset + 3 < r_length; i++) { if (nego[i] & FLAG_WILL) { reply[r_offset++] = 0xFF; /* IAC */ reply[r_offset++] = 0xFB; /* WILL */ reply[r_offset++] = (unsigned char)i; } if (nego[i] & FLAG_WONT) { reply[r_offset++] = 0xFF; /* IAC */ reply[r_offset++] = 0xFC; /* WONT */ reply[r_offset++] = (unsigned char)i; } if (nego[i] & FLAG_DO) { reply[r_offset++] = 0xFF; /* IAC */ reply[r_offset++] = 0xFD; /* DO */ reply[r_offset++] = (unsigned char)i; } if (nego[i] & FLAG_DONT) { reply[r_offset++] = 0xFF; /* IAC */ reply[r_offset++] = 0xFE; /* DONT */ reply[r_offset++] = (unsigned char)i; } } if (r_offset) { unsigned char *outbuf = MALLOC(r_offset); memcpy(outbuf, reply, r_offset); tcpapi_send(socket, outbuf, r_offset, TCP__copy); } } pstate->state = state; } /*************************************************************************** ***************************************************************************/ static void * telnet_init(struct Banner1 *banner1) { UNUSEDPARM(banner1); return 0; } /*************************************************************************** ***************************************************************************/ static int telnet_selftest_item(const char *input, const char *output) { struct Banner1 *banner1; struct StreamState pstate[1]; struct BannerOutput banout1[1]; int x; /* * Initiate a pseudo-environment for the parser */ banner1 = banner1_create(); banout_init(banout1); memset(&pstate[0], 0, sizeof(pstate[0])); /* * Parse the input payload */ telnet_parse(banner1, 0, pstate, (const unsigned char *)input, strlen(input), banout1, 0 ); //fprintf(stderr, "%.*s\n", (int)banout_string_length(banout1, PROTO_TELNET), banout_string(banout1, PROTO_TELNET)); /* * Verify that somewhere in the output is the string * we are looking for */ x = banout_is_contains(banout1, PROTO_TELNET, output); if (x == 0) printf("telnet parser failure: %s\n", output); banner1_destroy(banner1); banout_release(banout1); return (x==0)?1:0; } /*************************************************************************** ***************************************************************************/ static int telnet_selftest(void) { struct { const char *input; const char *output; } tests[] = { {"\xff\xfd\x1flogin:", "login:"}, {"\xff\xfd\x27\xff\xfd\x18 ", " "}, { "\xff\xfb\x25\xff\xfd\x03\xff\xfb\x18\xff\xfb\x1f\xff\xfb\x20\xff" \ "\xfb\x21\xff\xfb\x22\xff\xfb\x27\xff\xfd\x05" "\xff\xfb\x01\xff\xfb\x03\xff\xfd\x18\xff\xfd\x1f" "\xff\xfa\x18\x01\xff\xf0" "\x0d\x0a\x55\x73\x65\x72\x20\x41\x63\x63\x65\x73\x73\x20\x56\x65" \ "\x72\x69\x66\x69\x63\x61\x74\x69\x6f\x6e\x0d\x0a\x0d\x0a" , "User Access" }, { "\xff\xfd\x01\xff\xfd\x1f\xff\xfd\x21\xff\xfb\x01\xff\xfb\x03\x46" "\x36\x37\x30\x0d\x0a\x0d\x4c\x6f\x67\x69\x6e\x3a\x20", "F670\r\n\rLogin:" }, {0,0} }; size_t i; for (i=0; tests[i].input; i++) { int err; err = telnet_selftest_item(tests[i].input, tests[i].output); if (err) { fprintf(stderr, "telnet: selftest fail, item %u\n", (unsigned)i); return err; } } return 0; } /*************************************************************************** ***************************************************************************/ const struct ProtocolParserStream banner_telnet = { "telnet", 23, "\xff\xf6", 2, 0, telnet_selftest, telnet_init, telnet_parse, };
12,273
C
.c
334
26.056886
120
0.412895
robertdavidgraham/masscan
23,250
3,042
399
AGPL-3.0
9/7/2024, 9:40:14 AM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
5,311
out-record.h
robertdavidgraham_masscan/src/out-record.h
#ifndef OUT_RECORD_H #define OUT_RECORD_H enum OutputRecordType { Out_Open = 1, Out_Closed = 2, Out_Banner1 = 5, Out_Open2 = 6, Out_Closed2 = 7, Out_Arp2 = 8, Out_Banner9 = 9, Out_Open6 = 10, Out_Closed6 = 11, Out_Arp6 = 12, Out_Banner6 = 13, }; #endif
299
C
.c
16
14.8125
23
0.597865
robertdavidgraham/masscan
23,250
3,042
399
AGPL-3.0
9/7/2024, 9:40:14 AM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
5,313
stub-pcap-dlt.h
robertdavidgraham_masscan/src/stub-pcap-dlt.h
#ifndef STUB_PCAP_DLT_H #define STUB_PCAP_DLT_H typedef enum { /* Packets are prefixed by an integer indicating * the protocol type in host-byte-order (4-bytes) * followed by the raw IPv4 or IPv6 header */ PCAP_DLT_NULL = 0, /* Ethernet */ PCAP_DLT_ETHERNET = 1, /* Packets are 'raw' on the network. The first byte * will be the first byte of the IPv4/IPv6 header */ PCAP_DLT_RAW = 12, } pcap_dlt_t; #endif
424
C
.c
14
28.071429
53
0.71358
robertdavidgraham/masscan
23,250
3,042
399
AGPL-3.0
9/7/2024, 9:40:14 AM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
5,316
stack-if.c
robertdavidgraham_masscan/src/stack-if.c
#include "rawsock.h" #include "rawsock-adapter.h" /*************************************************************************** ***************************************************************************/ int stack_if_datalink(struct Adapter *adapter) { if (adapter->ring) return 1; /* ethernet */ else { return adapter->link_type; } }
365
C
.c
13
24.769231
77
0.364672
robertdavidgraham/masscan
23,250
3,042
399
AGPL-3.0
9/7/2024, 9:40:14 AM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
5,318
stack-tcp-app.c
robertdavidgraham_masscan/src/stack-tcp-app.c
#include "stack-tcp-app.h" #include "stack-tcp-api.h" #include "proto-banner1.h" #include "proto-ssl.h" #include "unusedparm.h" #include "util-malloc.h" #include "util-logger.h" #include "util-errormsg.h" #include <stdlib.h> enum { App_Connect, App_ReceiveHello, App_ReceiveNext, App_SendFirst, App_SendNext, App_Close, }; static const char *state_to_string(unsigned state) { switch (state) { case App_Connect: return "connect"; case App_ReceiveHello: return "wait-for-hello"; case App_ReceiveNext: return "receive"; case App_SendFirst: return "send-first"; case App_SendNext: return "send"; case App_Close: return "close"; default: return "unknown"; } } static const char *event_to_string(enum App_Event ev) { switch (ev) { case APP_CONNECTED: return "connected"; case APP_RECV_TIMEOUT: return "timeout"; case APP_RECV_PAYLOAD: return "payload"; case APP_SEND_SENT: return "sent"; case APP_CLOSE: return "close"; case APP_SENDING: return "sending"; default: return "unknown"; } } unsigned application_event(struct stack_handle_t *socket, unsigned state, enum App_Event event, const struct ProtocolParserStream *stream, struct Banner1 *banner1, const void *payload, size_t payload_length ) { again: switch (state) { case App_Connect: switch (event) { case APP_CONNECTED: /* We have a receive a SYNACK here. If there are multiple handlers * for this port, then attempt another connection using the * other protocol handlers. For example, for SSL, we might want * to try both TLSv1.0 and TLSv1.3 */ if (stream && stream->next) { tcpapi_reconnect(socket, stream->next, App_Connect); } /* * By default, wait for the "hello timeout" period * receiving any packets they send us. If nothing is * received in this period, then timeout will cause us * to switch to sending */ if (stream != NULL && (stream->flags & SF__nowait_hello) != 0) { tcpapi_change_app_state(socket, App_SendFirst); state = App_SendFirst; goto again; } else { tcpapi_set_timeout(socket, 2 /*tcpcon->timeout_hello*/, 0); tcpapi_recv(socket); tcpapi_change_app_state(socket, App_ReceiveHello); } break; default: ERRMSG("TCP.app: unhandled event: state=%s event=%s\n", state_to_string(state), event_to_string(event)); break; } break; case App_ReceiveHello: switch (event) { case APP_RECV_TIMEOUT: /* We've got no response from the initial connection, * so switch from them being responsible for communications * to us being responsible, and start sending */ if (stream) { tcpapi_change_app_state(socket, App_SendFirst); state = App_SendFirst; goto again; } break; case APP_RECV_PAYLOAD: /* We've receive some data from them, so wait for some more. * This means we won't be transmitting anything to them. */ tcpapi_change_app_state(socket, App_ReceiveNext); state = App_ReceiveNext; goto again; case APP_CLOSE: banner_flush(socket); tcpapi_close(socket); break; default: ERRMSG("TCP.app: unhandled event: state=%s event=%s\n", state_to_string(state), event_to_string(event)); break; } break; case App_ReceiveNext: switch (event) { case APP_RECV_PAYLOAD: /* [--banners] * This is an important part of the system, where the TCP * stack passes incoming packet payloads off to the application * layer protocol parsers. This is where, in Sockets API, you * might call the 'recv()' function. */ banner_parse(socket, payload, payload_length ); break; case APP_CLOSE: /* The other side has sent us a FIN, therefore, we need * to likewise close our end. */ banner_flush(socket); tcpapi_close(socket); break; case APP_RECV_TIMEOUT: break; case APP_SENDING: /* A higher level protocol has started sending packets while processing * a receive, therefore, change to the SEND state */ tcpapi_change_app_state(socket, App_SendNext); break; case APP_SEND_SENT: /* FIXME */ break; default: ERRMSG("TCP.app: unhandled event: state=%s event=%s\n", state_to_string(state), event_to_string(event)); break; } break; case App_SendFirst: /* This isn't called from the outside, but from one of the * states internally whhen we transmit for the first time */ if (stream == &banner_ssl || stream == &banner_ssl_12) { /* * Kludge, extreme kludge * I don't even know what this does any longer */ banner_set_sslhello(socket, true); } if (banner_is_heartbleed(socket)) { /* * Kludge, extreme kludge * I don't even know what this does any longer */ banner_set_small_window(socket, true); } /* * We either have a CALLBACK that will handle the * sending/receiving of packets, or we will send a fixed * "probe" string that will hopefull trigger a response. */ if (stream && stream->transmit_hello) { /* We have a callback function for the protocol stream that will * craft a packet, such as maybe generate an HTTP request containing * valid "Host:" field. */ stream->transmit_hello(banner1, socket); } else if (stream && stream->hello_length) { /* We just have a template to blindly copy some bytes onto the wire * in order to trigger/probe for a response */ tcpapi_send(socket, stream->hello, stream->hello_length, TCP__static); /* If specified, then send a FIN right after the hello data. * This will complete a reponse faster from the server. */ if ((stream->flags & SF__close) != 0) tcpapi_close(socket); } tcpapi_change_app_state(socket, App_SendNext); break; case App_SendNext: switch (event) { case APP_SEND_SENT: /* We've got an acknowledgement that all our data * was sent. Therefore, change the receive state */ tcpapi_recv(socket); tcpapi_change_app_state(socket, App_ReceiveNext); break; case APP_SENDING: break; default: ERRMSG("TCP.app: unhandled event: state=%s event=%s\n", state_to_string(state), event_to_string(event)); break; } break; default: ERRMSG("TCP.app: unhandled event: state=%s event=%s\n", state_to_string(state), event_to_string(event)); break; } return 0; }
8,682
C
.c
205
26.878049
91
0.495213
robertdavidgraham/masscan
23,250
3,042
399
AGPL-3.0
9/7/2024, 9:40:14 AM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
5,322
util-checksum.h
robertdavidgraham_masscan/src/util-checksum.h
/* Calculates Internet checksums for protocols like TCP/IP. Author: Robert David Graham Copyright: 2020 License: The MIT License (MIT) Dependencies: none */ #ifndef UTIL_CHECKSUM_H #define UTIL_CHECKSUM_H #include <stddef.h> /** * Calculate a checksum for IPv4 packets. * @param ip_src * The source IPv4 address, represented a standard way, * as a 32-bit integer in host byte order. * @param ip_dst * The destination IPv4 address, represented as a 32-bit integer in host byte order. * @param ip_proto * A value of 6 for TCP or 17 for UDP. * @param payload_length * The length of the IP packet payload, meaning, everything after the IPv4 header. * In other words, it's the "total length" field of the IP packet minus the * length of the IP header. * @param payload * A pointer to the aforementioned payload (a pointer to the first byte past the * IP header). Note that the calculation skips the checksum field, so the payload * we use is everything but the 2 bytes in the checksum field. Thus, due to the * quirkiness of Internet protocols, the result of this calculation should end * up equally the value of the checksum field. * @return * the calculated checksum, which should equal the checksum found in the payload */ unsigned checksum_ipv4(unsigned ip_src, unsigned ip_dst, unsigned ip_proto, size_t payload_length, const void *payload); unsigned checksum_ipv6(const unsigned char *ip_src, const unsigned char *ip_dst, unsigned ip_proto, size_t payload_length, const void *payload); /** * Simple unit tests. * @return * 1 if failure, 0 if success */ int checksum_selftest(void); #endif
1,714
C
.c
43
37.604651
135
0.722523
robertdavidgraham/masscan
23,250
3,042
399
AGPL-3.0
9/7/2024, 9:40:14 AM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
5,323
in-filter.c
robertdavidgraham_masscan/src/in-filter.c
#include "in-filter.h" #include "massip.h" int readscan_filter_pass(ipaddress ip, unsigned port, unsigned type, const struct MassIP *filter, const struct RangeList *btypes) { if (filter && filter->count_ipv4s) { if (!massip_has_ip(filter, ip)) return 0; } if (filter && filter->count_ports) { if (!massip_has_port(filter, port)) return 0; } if (btypes && btypes->count) { if (!rangelist_is_contains(btypes, type)) return 0; } return 1; }
557
C
.c
21
19.857143
64
0.575985
robertdavidgraham/masscan
23,250
3,042
399
AGPL-3.0
9/7/2024, 9:40:14 AM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
5,325
stack-tcp-api.h
robertdavidgraham_masscan/src/stack-tcp-api.h
#ifndef STACK_HANDLE_H #define STACK_HANDLE_H #include <stdio.h> #include "util-bool.h" /* <stdbool.h> */ struct ProtocolParserStream; enum TCP__flags { TCP__static,/* it's static data, so the send function can point to it */ TCP__copy, /* the send function must copy the data */ TCP__adopt, /* the buffer was just allocated, so the send function can adopt the pointer */ TCP__close_fin /* close connection */ }; enum { SOCKERR_NONE=0, /* no error */ SOCKERR_EBADF=10, /* bad socket descriptor */ }; typedef struct stack_handle_t { void *tcpcon; void *tcb; unsigned secs; unsigned usecs; } stack_handle_t; /** * Set a new default timeout. */ int tcpapi_set_timeout(struct stack_handle_t *socket, unsigned secs, unsigned usecs ); /** * Change from the "send" state to the "receive" state. * Has no effect if in any state other than "send". * This is none-blocking, an event will be triggered * later that has the data. */ int tcpapi_recv(struct stack_handle_t *socket); int tcpapi_send(struct stack_handle_t *socket, const void *buf, size_t length, enum TCP__flags flags); /** * Re-connect to the target, same IP and port, creating a new connection * from a different port on this side. */ int tcpapi_reconnect(struct stack_handle_t *old_socket, struct ProtocolParserStream *new_stream, unsigned new_app_state); /** * The "app state" variable is stored opaquely in the `tcb` structure, so * to reset it, we need an access function. */ unsigned tcpapi_change_app_state(struct stack_handle_t *socket, unsigned new_app_state); /** Perform the sockets half-close function (calling `close()`). This * doesn't actually get rid of the socket, but only stops sending. * It sends a FIN packet to the other side, and transitions to the * TCP CLOSE-WAIT state. * The socket will continue to receive from the opposing side until they * give us a FIN packet. */ int tcpapi_close(struct stack_handle_t *socket); #endif
2,096
C
.c
64
28.796875
96
0.687996
robertdavidgraham/masscan
23,250
3,042
399
AGPL-3.0
9/7/2024, 9:40:14 AM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
5,326
out-hostonly.c
robertdavidgraham_masscan/src/out-hostonly.c
#include "output.h" #include "masscan.h" #include "masscan-app.h" #include "masscan-status.h" #include "unusedparm.h" #include "out-tcp-services.h" static void hostonly_out_open(struct Output *out, FILE *fp) { UNUSEDPARM(fp); UNUSEDPARM(out); } static void hostonly_out_close(struct Output *out, FILE *fp) { UNUSEDPARM(fp); UNUSEDPARM(out); } static void hostonly_out_status(struct Output *out, FILE *fp, time_t timestamp, int status, ipaddress ip, unsigned ip_proto, unsigned port, unsigned reason, unsigned ttl) { ipaddress_formatted_t fmt = ipaddress_fmt(ip); UNUSEDPARM(reason); UNUSEDPARM(out); UNUSEDPARM(timestamp); UNUSEDPARM(ttl); UNUSEDPARM(port); UNUSEDPARM(ip_proto); UNUSEDPARM(status); fprintf(fp, "%s\n", fmt.string); } /*************************************** ************************************* ****************************************************************************/ static void hostonly_out_banner(struct Output *out, FILE *fp, time_t timestamp, ipaddress ip, unsigned ip_proto, unsigned port, enum ApplicationProtocol proto, unsigned ttl, const unsigned char *px, unsigned length) { /* SYN only - no banner */ ipaddress_formatted_t fmt = ipaddress_fmt(ip); UNUSEDPARM(out); UNUSEDPARM(ttl); UNUSEDPARM(port); UNUSEDPARM(fp); UNUSEDPARM(timestamp); UNUSEDPARM(ip); UNUSEDPARM(ip_proto); UNUSEDPARM(proto); UNUSEDPARM(px); UNUSEDPARM(length); fprintf(fp, "%s\n", fmt.string); return; } /**************************************************************************** ****************************************************************************/ const struct OutputType hostonly_output = { "hostonly", 0, hostonly_out_open, hostonly_out_close, hostonly_out_status, hostonly_out_banner };
1,886
C
.c
64
25.703125
94
0.58204
robertdavidgraham/masscan
23,250
3,042
399
AGPL-3.0
9/7/2024, 9:40:14 AM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
5,330
util-logger.c
robertdavidgraham_masscan/src/util-logger.c
/* log messages to console, depending on verbose level Use -d to get more verbose output. The more -v you add, the more verbose the output becomes. Details about the running of the program go to <stderr>. Details about scan results go to <stdout>, so that they can easily be redirected to a file. */ #include "util-logger.h" #include "util-safefunc.h" #include <stdarg.h> #include <stdio.h> static int global_debug_level = 0; /* yea! a global variable!! */ void LOG_add_level(int x) { global_debug_level += x; } /*************************************************************************** ***************************************************************************/ static void vLOG(int level, const char *fmt, va_list marker) { if (level <= global_debug_level) { vfprintf(stderr, fmt, marker); fflush(stderr); } } /*************************************************************************** * Prints the message if the global "verbosity" flag exceeds this level. ***************************************************************************/ void LOG(int level, const char *fmt, ...) { va_list marker; va_start(marker, fmt); vLOG(level, fmt, marker); va_end(marker); } /*************************************************************************** ***************************************************************************/ static void vLOGnet(unsigned port_me, ipaddress ip_them, const char *fmt, va_list marker) { char sz_ip[64]; ipaddress_formatted_t fmt1 = ipaddress_fmt(ip_them); snprintf(sz_ip, sizeof(sz_ip), "%s", fmt1.string); fprintf(stderr, "%u:%s: ", port_me, sz_ip); vfprintf(stderr, fmt, marker); fflush(stderr); } void LOGnet(unsigned port_me, ipaddress ip_them, const char *fmt, ...) { va_list marker; va_start(marker, fmt); vLOGnet(port_me, ip_them, fmt, marker); va_end(marker); } /*************************************************************************** ***************************************************************************/ static void vLOGip(int level, ipaddress ip, unsigned port, const char *fmt, va_list marker) { if (level <= global_debug_level) { char sz_ip[64]; ipaddress_formatted_t fmt1 = ipaddress_fmt(ip); snprintf(sz_ip, sizeof(sz_ip), "%s:%u: ", fmt1.string, port); fprintf(stderr, "%s ", sz_ip); vfprintf(stderr, fmt, marker); fflush(stderr); } } void LOGip(int level, ipaddress ip, unsigned port, const char *fmt, ...) { va_list marker; va_start(marker, fmt); vLOGip(level, ip, port, fmt, marker); va_end(marker); }
2,659
C
.c
80
29.725
79
0.506438
robertdavidgraham/masscan
23,250
3,042
399
AGPL-3.0
9/7/2024, 9:40:14 AM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
5,331
stack-queue.c
robertdavidgraham_masscan/src/stack-queue.c
#include "stack-queue.h" #include "pixie-timer.h" #include "rawsock.h" #include "util-malloc.h" #include <string.h> #include <stdio.h> struct PacketBuffer * stack_get_packetbuffer(struct stack_t *stack) { int err; struct PacketBuffer *response = NULL; for (err=1; err; ) { err = rte_ring_sc_dequeue(stack->packet_buffers, (void**)&response); if (err != 0) { /* Pause and wait for a buffer to become available */ pixie_usleep(1000); } } return response; } void stack_transmit_packetbuffer(struct stack_t *stack, struct PacketBuffer *response) { int err; for (err=1; err; ) { err = rte_ring_sp_enqueue(stack->transmit_queue, response); if (err) { fprintf(stderr, "[-] transmit queue full (should be impossible)\n"); pixie_usleep(1000); } } } /*************************************************************************** * The receive thread doesn't transmit packets. Instead, it queues them * up on the transmit thread. Every so often, the transmit thread needs * to flush this transmit queue and send everything. * * This is an inherent design issue trying to send things as batches rather * than individually. It increases latency, but increases performance. We * don't really care about latency. ***************************************************************************/ void stack_flush_packets( struct stack_t *stack, struct Adapter *adapter, uint64_t *packets_sent, uint64_t *batchsize) { /* * Send a batch of queued packets */ for ( ; (*batchsize); (*batchsize)--) { int err; struct PacketBuffer *p; /* * Get the next packet from the transmit queue. This packet was * put there by a receive thread, and will contain things like * an ACK or an HTTP request */ err = rte_ring_sc_dequeue(stack->transmit_queue, (void**)&p); if (err) { break; /* queue is empty, nothing to send */ } /* * Actually send the packet */ rawsock_send_packet(adapter, p->px, (unsigned)p->length, 1); /* * Now that we are done with the packet, put it on the free list * of buffers that the transmit thread can reuse */ for (err=1; err; ) { err = rte_ring_sp_enqueue(stack->packet_buffers, p); if (err) { fprintf(stderr, "[-] transmit queue full (should be impossible)\n"); pixie_usleep(10000); } } /* * Remember that we sent a packet, which will be used in * throttling. */ (*packets_sent)++; } } struct stack_t * stack_create(macaddress_t source_mac, struct stack_src_t *src) { struct stack_t *stack; size_t i; stack = CALLOC(1, sizeof(*stack)); stack->source_mac = source_mac; stack->src = src; /* * Allocate packet buffers for sending */ #define BUFFER_COUNT 16384 stack->packet_buffers = rte_ring_create(BUFFER_COUNT, RING_F_SP_ENQ|RING_F_SC_DEQ); stack->transmit_queue = rte_ring_create(BUFFER_COUNT, RING_F_SP_ENQ|RING_F_SC_DEQ); for (i=0; i<BUFFER_COUNT-1; i++) { struct PacketBuffer *p; int err; p = MALLOC(sizeof(*p)); err = rte_ring_sp_enqueue(stack->packet_buffers, p); if (err) { /* I dunno why but I can't queue all 256 packets, just 255 */ fprintf(stderr, "[-] packet_buffers: enqueue: error %d\n", err); } } return stack; }
3,628
C
.c
111
26.18018
87
0.577759
robertdavidgraham/masscan
23,250
3,042
399
AGPL-3.0
9/7/2024, 9:40:14 AM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
5,333
misc-rstfilter.c
robertdavidgraham_masscan/src/misc-rstfilter.c
#include "misc-rstfilter.h" #include "util-malloc.h" #include "crypto-siphash24.h" #include <time.h> struct ResetFilter { unsigned long long seed; size_t bucket_count; size_t bucket_mask; unsigned counter; unsigned char *buckets; }; static size_t next_pow2(size_t n) { size_t bit_count = 0; /* Always have at least one bit */ if (n == 0) return 1; /* If already a power-of-two, then return that */ if ((n & (n - 1)) == 0) return n; /* Count the number of bits */ while (n != 0) { n >>= 1; bit_count += 1; } return (size_t)1 << (size_t)bit_count; } struct ResetFilter * rstfilter_create(unsigned long long seed, size_t bucket_count) { struct ResetFilter *rf; rf = CALLOC(1, sizeof(*rf)); rf->seed = seed; rf->bucket_count = next_pow2(bucket_count); rf->bucket_mask = rf->bucket_count - 1; rf->buckets = CALLOC(rf->bucket_count/2, sizeof(*rf->buckets)); return rf; } void rstfilter_destroy(struct ResetFilter *rf) { if (rf == NULL) return; free(rf->buckets); free(rf); } int rstfilter_is_filter(struct ResetFilter *rf, ipaddress src_ip, unsigned src_port, ipaddress dst_ip, unsigned dst_port) { uint64_t hash; uint64_t input[5]; uint64_t key[2]; size_t index; unsigned char *p; int result = 0; /* * Setup the input */ switch (src_ip.version) { case 4: input[0] = src_ip.ipv4; input[1] = src_port; input[2] = dst_ip.ipv4; input[3] = dst_port; break; case 6: input[0] = src_ip.ipv6.hi; input[1] = src_ip.ipv6.lo; input[2] = dst_ip.ipv6.hi; input[3] = dst_ip.ipv6.lo; input[4] = src_port<<16 | dst_port; break; } key[0] = rf->seed; key[1] = rf->seed; /* * Grab the bucket */ hash = siphash24(input, sizeof(input), key); index = hash & rf->bucket_mask; /* * Find the result (1=filterout, 0=sendrst) */ p = &rf->buckets[index/2]; if (index & 1) { if ((*p & 0x0F) == 0x0F) result = 1; /* filter out */ else *p = (*p) + 0x01; } else { if ((*p & 0xF0) == 0xF0) result = 1; /* filter out */ else *p = (*p) + 0x10; } /* * Empty a random bucket */ input[0] = (unsigned)hash; input[1] = rf->counter++; hash = siphash24(input, sizeof(input), key); index = hash & rf->bucket_mask; p = &rf->buckets[index/2]; if (index & 1) { if ((*p & 0x0F)) *p = (*p) - 0x01; } else { if ((*p & 0xF0)) *p = (*p) - 0x10; } return result; } int rstfilter_selftest(void) { struct ResetFilter *rf; size_t i; unsigned count_filtered = 0; unsigned count_passed = 0; ipaddress src; ipaddress dst; src.version = 4; src.ipv4 = 1; dst.version = 4; dst.ipv4 = 3; rf = rstfilter_create(time(0), 64); /* Verify the first 15 packets pass the filter */ for (i=0; i<15; i++) { int x; x = rstfilter_is_filter(rf, src, 2, dst, 4); if (x) { fprintf(stderr, "[-] rstfilter failed, line=%u\n", __LINE__); return 1; } } /* Now run 10000 more times */ for (i=0; i<1000; i++) { int x; x = rstfilter_is_filter(rf, src, 2, dst, 4); count_filtered += x; count_passed += !x; } /* SOME must have passed, due to us emptying random buckets */ if (count_passed == 0) { fprintf(stderr, "[-] rstfilter failed, line=%u\n", __LINE__); return 1; } /* However, while some pass, the vast majority should be filtered */ if (count_passed > count_filtered/10) { fprintf(stderr, "[-] rstfilter failed, line=%u\n", __LINE__); return 1; } //printf("filtered=%u passed=%u\n", count_filtered, count_passed); return 0; }
4,100
C
.c
159
19.383648
73
0.54026
robertdavidgraham/masscan
23,250
3,042
399
AGPL-3.0
9/7/2024, 9:40:14 AM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
5,334
util-extract.h
robertdavidgraham_masscan/src/util-extract.h
#ifndef UTIL_EXTRACT_H #define UTIL_EXTRACT_H #include <stdio.h> struct ebuf_t { const unsigned char *buf; size_t offset; size_t max; }; enum { EBUF_BE, EBUG_LE, }; unsigned char e_next_byte(struct ebuf_t *ebuf); unsigned short e_next_short16(struct ebuf_t *ebuf, int endian); unsigned e_next_int32(struct ebuf_t *ebuf, int endian); unsigned long long e_next_long64(struct ebuf_t *ebuf, int endian); #endif
432
C
.c
17
22.941176
66
0.726829
robertdavidgraham/masscan
23,250
3,042
399
AGPL-3.0
9/7/2024, 9:40:14 AM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
5,336
rawsock.c
robertdavidgraham_masscan/src/rawsock.c
/* portable interface to "raw sockets" This uses both "libpcap" on systems, but on Linux, we try to use the basic raw sockets, bypassing libpcap for better performance. */ #include "rawsock.h" #include "templ-pkt.h" #include "util-logger.h" #include "main-ptrace.h" #include "util-safefunc.h" #include "stub-pcap.h" #include "stub-pfring.h" #include "pixie-timer.h" #include "main-globals.h" #include "proto-preprocess.h" #include "stack-arpv4.h" #include "stack-ndpv6.h" #include "unusedparm.h" #include "util-malloc.h" #include <assert.h> #include <ctype.h> static int is_pcap_file = 0; #ifdef WIN32 #include <winsock.h> #include <iphlpapi.h> #if defined(_MSC_VER) #pragma comment(lib, "IPHLPAPI.lib") #endif #elif defined(__GNUC__) #include <unistd.h> #include <sys/types.h> #include <sys/socket.h> #include <sys/ioctl.h> #include <netinet/in.h> #include <net/if.h> #include <arpa/inet.h> #else #endif #include "rawsock-adapter.h" #define SENDQ_SIZE 65536 * 8 struct AdapterNames { char *easy_name; char *hard_name; }; struct AdapterNames adapter_names[64]; unsigned adapter_name_count = 0; /*************************************************************************** ***************************************************************************/ #ifdef WIN32 int pcap_setdirection(pcap_t *pcap, pcap_direction_t direction) { static int (*real_setdirection)(pcap_t *, pcap_direction_t) = 0; if (real_setdirection == 0) { void* h = LoadLibraryA("wpcap.dll"); if (h == NULL) { fprintf(stderr, "couldn't load wpcap.dll: %u\n", (unsigned)GetLastError()); return -1; } real_setdirection = (int (*)(pcap_t*,pcap_direction_t)) GetProcAddress(h, "pcap_setdirection"); if (real_setdirection == 0) { fprintf(stderr, "couldn't find pcap_setdirection(): %u\n", (unsigned)GetLastError()); return -1; } } return real_setdirection(pcap, direction); } #endif /*************************************************************************** ***************************************************************************/ void rawsock_init(void) { #ifdef WIN32 /* Declare and initialize variables */ // It is possible for an adapter to have multiple // IPv4 addresses, gateways, and secondary WINS servers // assigned to the adapter. // // Note that this sample code only prints out the // first entry for the IP address/mask, and gateway, and // the primary and secondary WINS server for each adapter. PIP_ADAPTER_INFO pAdapterInfo; PIP_ADAPTER_INFO pAdapter = NULL; DWORD dwRetVal = 0; UINT i; /* variables used to print DHCP time info */ //struct tm newtime; //char buffer[32]; ULONG ulOutBufLen = sizeof (IP_ADAPTER_INFO); pAdapterInfo = (IP_ADAPTER_INFO *) malloc(sizeof (IP_ADAPTER_INFO)); if (pAdapterInfo == NULL) { printf("Error allocating memory needed to call GetAdaptersinfo\n"); return; } // Make an initial call to GetAdaptersInfo to get // the necessary size into the ulOutBufLen variable if (GetAdaptersInfo(pAdapterInfo, &ulOutBufLen) == ERROR_BUFFER_OVERFLOW) { free(pAdapterInfo); pAdapterInfo = (IP_ADAPTER_INFO *) malloc(ulOutBufLen); if (pAdapterInfo == NULL) { printf("Error allocating memory needed to call GetAdaptersinfo\n"); return; } } if ((dwRetVal = GetAdaptersInfo(pAdapterInfo, &ulOutBufLen)) == NO_ERROR) { for (pAdapter = pAdapterInfo; pAdapter; pAdapter = pAdapter->Next) { if (pAdapter->Type != MIB_IF_TYPE_ETHERNET) continue; //printf("\tComboIndex: \t%d\n", pAdapter->ComboIndex); //printf("\tAdapter Name: \t%s\n", pAdapter->AdapterName); { size_t name_len = strlen(pAdapter->AdapterName) + 12 + 1; char *name = (char*)malloc(name_len); size_t addr_len = pAdapter->AddressLength * 3 + 1; char *addr = (char*)malloc(addr_len); if (name == NULL || addr == NULL) exit(1); snprintf(name, name_len, "\\Device\\NPF_%s", pAdapter->AdapterName); //printf("\tAdapter Desc: \t%s\n", pAdapter->Description); //printf("\tAdapter Addr: \t"); for (i = 0; i < pAdapter->AddressLength; i++) { if (i == (pAdapter->AddressLength - 1)) snprintf(addr+i*3, addr_len-i*3, "%.2X", pAdapter->Address[i]); else snprintf(addr+i*3, addr_len-i*3, "%.2X-", pAdapter->Address[i]); } //printf("%s -> %s\n", addr, name); adapter_names[adapter_name_count].easy_name = addr; adapter_names[adapter_name_count].hard_name = name; adapter_name_count++; } //printf("\tIndex: \t%d\n", pAdapter->Index); { size_t name_len = strlen(pAdapter->AdapterName) + 12 + 1; char *name = (char*)malloc(name_len); size_t addr_len = strlen(pAdapter->IpAddressList.IpAddress.String) + 1; char *addr = (char*)malloc(addr_len); if (name == NULL || addr == NULL) exit(1); snprintf(name, name_len, "\\Device\\NPF_%s", pAdapter->AdapterName); snprintf(addr, addr_len, "%s", pAdapter->IpAddressList.IpAddress.String); //printf("%s -> %s\n", addr, name); adapter_names[adapter_name_count].easy_name = addr; adapter_names[adapter_name_count].hard_name = name; adapter_name_count++; } } } else { printf("GetAdaptersInfo failed with error: %u\n", (unsigned)dwRetVal); } if (pAdapterInfo) free(pAdapterInfo); #else PFRING_init(); #endif return; } /*************************************************************************** * This function prints to the command line a list of all the network * interfaces/devices. ***************************************************************************/ void rawsock_list_adapters(void) { pcap_if_t *alldevs; char errbuf[PCAP_ERRBUF_SIZE]; if (PCAP.findalldevs(&alldevs, errbuf) != -1) { int i; const pcap_if_t *d; i=0; if (alldevs == NULL) { fprintf(stderr, "ERR:libpcap: no adapters found, are you sure you are root?\n"); } /* Print the list */ for(d=alldevs; d; d=PCAP.dev_next(d)) { fprintf(stderr, " %d %s \t", i++, PCAP.dev_name(d)); if (PCAP.dev_description(d)) fprintf(stderr, "(%s)\n", PCAP.dev_description(d)); else fprintf(stderr, "(No description available)\n"); } fprintf(stderr,"\n"); PCAP.freealldevs(alldevs); } else { fprintf(stderr, "%s\n", errbuf); } } /*************************************************************************** ***************************************************************************/ static const char * adapter_from_index(unsigned index) { pcap_if_t *alldevs; char errbuf[PCAP_ERRBUF_SIZE]; int x; x = PCAP.findalldevs(&alldevs, errbuf); if (x != -1) { const pcap_if_t *d; if (alldevs == NULL) { fprintf(stderr, "ERR:libpcap: no adapters found, are you sure you are root?\n"); } /* Print the list */ for(d=alldevs; d; d=PCAP.dev_next(d)) { if (index-- == 0) return PCAP.dev_name(d); } return 0; } else { return 0; } } /*************************************************************************** * Some methods of transmit queue multiple packets in a buffer then * send all queued packets at once. At the end of a scan, we might have * some pending packets that haven't been transmitted yet. Therefore, * we'll have to flush them. ***************************************************************************/ void rawsock_flush(struct Adapter *adapter) { if (adapter->sendq) { PCAP.sendqueue_transmit(adapter->pcap, adapter->sendq, 0); /* Dude, I totally forget why this step is necessary. I vaguely * remember there's a good reason for it though */ PCAP.sendqueue_destroy(adapter->sendq); adapter->sendq = PCAP.sendqueue_alloc(SENDQ_SIZE); } } /*************************************************************************** * wrapper for libpcap's sendpacket * * PORTABILITY: WINDOWS and PF_RING * For performance, Windows and PF_RING can queue up multiple packets, then * transmit them all in a chunk. If we stop and wait for a bit, we need * to flush the queue to force packets to be transmitted immediately. ***************************************************************************/ int rawsock_send_packet( struct Adapter *adapter, const unsigned char *packet, unsigned length, unsigned flush) { /* Why: this happens in "offline mode", when we are benchmarking the * core algorithms without sending packets. */ if (adapter == 0) return 0; /* Print --packet-trace if debugging */ if (adapter->is_packet_trace) { packet_trace(stdout, adapter->pt_start, packet, length, 1); } /* PF_RING */ if (adapter->ring) { int err = PF_RING_ERROR_NO_TX_SLOT_AVAILABLE; while (err == PF_RING_ERROR_NO_TX_SLOT_AVAILABLE) { err = PFRING.send(adapter->ring, packet, length, (unsigned char)flush); } if (err < 0) LOG(1, "pfring:xmit: ERROR %d\n", err); return err; } /* WINDOWS PCAP */ if (adapter->sendq) { int err; struct pcap_pkthdr hdr; hdr.len = length; hdr.caplen = length; err = PCAP.sendqueue_queue(adapter->sendq, &hdr, packet); if (err) { rawsock_flush(adapter); PCAP.sendqueue_queue(adapter->sendq, &hdr, packet); } if (flush) { rawsock_flush(adapter); } return 0; } /* LIBPCAP */ if (adapter->pcap) return PCAP.sendpacket(adapter->pcap, packet, length); return 0; } /*************************************************************************** ***************************************************************************/ int rawsock_recv_packet( struct Adapter *adapter, unsigned *length, unsigned *secs, unsigned *usecs, const unsigned char **packet) { if (adapter->ring) { /* This is for doing libpfring instead of libpcap */ struct pfring_pkthdr hdr; int err; again: err = PFRING.recv(adapter->ring, (unsigned char**)packet, 0, /* zero-copy */ &hdr, 0 /* return immediately */ ); if (err == PF_RING_ERROR_NO_PKT_AVAILABLE || hdr.caplen == 0) { PFRING.poll(adapter->ring, 1); if (is_tx_done) return 1; goto again; } if (err) return 1; *length = hdr.caplen; *secs = (unsigned)hdr.ts.tv_sec; *usecs = (unsigned)hdr.ts.tv_usec; } else if (adapter->pcap) { struct pcap_pkthdr hdr; *packet = PCAP.next(adapter->pcap, &hdr); if (*packet == NULL) { if (is_pcap_file) { //pixie_time_set_offset(10*100000); is_tx_done = 1; is_rx_done = 1; } return 1; } *length = hdr.caplen; *secs = (unsigned)hdr.ts.tv_sec; *usecs = (unsigned)hdr.ts.tv_usec; } return 0; } /*************************************************************************** * Sends the TCP SYN probe packet. * * Step 1: format the packet * Step 2: send it in a portable manner ***************************************************************************/ void rawsock_send_probe_ipv4( struct Adapter *adapter, ipv4address ip_them, unsigned port_them, ipv4address ip_me, unsigned port_me, unsigned seqno, unsigned flush, struct TemplateSet *tmplset) { unsigned char px[2048]; size_t packet_length; /* * Construct the destination packet */ template_set_target_ipv4(tmplset, ip_them, port_them, ip_me, port_me, seqno, px, sizeof(px), &packet_length); /* * Send it */ rawsock_send_packet(adapter, px, (unsigned)packet_length, flush); } void rawsock_send_probe_ipv6( struct Adapter *adapter, ipv6address ip_them, unsigned port_them, ipv6address ip_me, unsigned port_me, unsigned seqno, unsigned flush, struct TemplateSet *tmplset) { unsigned char px[2048]; size_t packet_length; /* * Construct the destination packet */ template_set_target_ipv6(tmplset, ip_them, port_them, ip_me, port_me, seqno, px, sizeof(px), &packet_length); /* * Send it */ rawsock_send_packet(adapter, px, (unsigned)packet_length, flush); } /*************************************************************************** * Used on Windows: network adapters have horrible names, so therefore we * use numeric indexes instead. You can which adapter you are looking for * by typing "--iflist" as an option. ***************************************************************************/ static int is_numeric_index(const char *ifname) { int result = 1; int i; /* empty strings aren't numbers */ if (ifname[0] == '\0') return 0; /* 'true' if all digits */ for (i=0; ifname[i]; i++) { char c = ifname[i]; if (c < '0' || '9' < c) result = 0; } return result; } /*************************************************************************** * Used on Windows: if the adapter name is a numeric index, convert it to * the full name. ***************************************************************************/ const char * rawsock_win_name(const char *ifname) { if (is_numeric_index(ifname)) { const char *new_adapter_name; new_adapter_name = adapter_from_index(atoi(ifname)); if (new_adapter_name) return new_adapter_name; } return ifname; } /*************************************************************************** * Configure the socket to not capture transmitted packets. This is needed * because we transmit packets at a rate of millions per second, which will * overwhelm the receive thread. * * PORTABILITY: Windows doesn't seem to support this feature, so instead * what we do is apply a BPF filter to ignore the transmits, so that they * still get filtered at a low level. ***************************************************************************/ void rawsock_ignore_transmits(struct Adapter *adapter, const char *ifname) { if (adapter->ring) { /* PORTABILITY: don't do anything for PF_RING, because it's * actually done when we create the adapter, because we can't * reconfigure the adapter after it's been activated. */ return; } if (adapter->pcap) { int err; err = PCAP.setdirection(adapter->pcap, PCAP_D_IN); if (err) { ; //PCAP.perror(adapter->pcap, "if: pcap_setdirection(IN)"); } else { LOG(2, "if:%s: not receiving transmits\n", ifname); } } } /*************************************************************************** ***************************************************************************/ static void rawsock_close_adapter(struct Adapter *adapter) { if (adapter->ring) { PFRING.close(adapter->ring); } if (adapter->pcap) { PCAP.close(adapter->pcap); } if (adapter->sendq) { PCAP.sendqueue_destroy(adapter->sendq); } free(adapter); } /*************************************************************************** * Does the name look like a PF_RING DNA adapter? Common names are: * dna0 * dna1 * dna0@1 * ***************************************************************************/ static int is_pfring_dna(const char *name) { if (strlen(name) < 4) return 0; if (memcmp(name, "zc:", 3) == 0) return 1; if (memcmp(name, "dna", 3) != 0) return 0; name +=3; if (!isdigit(name[0]&0xFF)) return 0; while (isdigit(name[0]&0xFF)) name++; if (name[0] == '\0') return 1; if (name[0] != '@') return 0; else name++; if (!isdigit(name[0]&0xFF)) return 0; while (isdigit(name[0]&0xFF)) name++; if (name[0] == '\0') return 1; else return 0; } /*************************************************************************** ***************************************************************************/ struct Adapter * rawsock_init_adapter(const char *adapter_name, unsigned is_pfring, unsigned is_sendq, unsigned is_packet_trace, unsigned is_offline, const char *bpf_filter, unsigned is_vlan, unsigned vlan_id) { struct Adapter *adapter; char errbuf[PCAP_ERRBUF_SIZE] = "pcap"; /* BPF filter not supported on some platforms, so ignore this compiler * warning when unused */ UNUSEDPARM(bpf_filter); adapter = CALLOC(1, sizeof(*adapter)); adapter->is_packet_trace = is_packet_trace; adapter->pt_start = 1.0 * pixie_gettime() / 1000000.0; adapter->is_vlan = is_vlan; adapter->vlan_id = vlan_id; if (is_offline) return adapter; /*---------------------------------------------------------------- * PORTABILITY: WINDOWS * If is all digits index, then look in indexed list *----------------------------------------------------------------*/ if (is_numeric_index(adapter_name)) { const char *new_adapter_name; new_adapter_name = adapter_from_index(atoi(adapter_name)); if (new_adapter_name == 0) { fprintf(stderr, "pcap_open_live(%s) error: bad index\n", adapter_name); return 0; } else adapter_name = new_adapter_name; } /*---------------------------------------------------------------- * PORTABILITY: PF_RING * If we've been told to use --pfring, then attempt to open the * network adapter using the PF_RING API rather than libpcap. * Since a lot of things can go wrong, we do a lot of extra * logging here. *----------------------------------------------------------------*/ if(is_pfring && !is_pfring_dna(adapter_name)){ /*First ensure pfring dna adapter is available*/ fprintf(stderr,"No pfring adapter available. Please install pfring or run masscan without the --pfring option.\n"); return 0; } if (is_pfring_dna(adapter_name)) { int err; unsigned version; /* * Open * * TODO: Do we need the PF_RING_REENTRANT flag? We only have one * transmit and one receive thread, so I don't think we need it. * Also, this reduces performance in half, from 12-mpps to * 6-mpps. * NOTE: I don't think it needs the "re-entrant" flag, because it * transmit and receive are separate functions? */ LOG(2, "pfring:'%s': opening...\n", adapter_name); adapter->ring = PFRING.open(adapter_name, 1500, 0);//PF_RING_REENTRANT); adapter->pcap = (pcap_t*)adapter->ring; adapter->link_type = 1; if (adapter->ring == NULL) { LOG(0, "pfring:'%s': OPEN ERROR: %s\n", adapter_name, strerror(errno)); return 0; } else LOG(1, "pfring:'%s': successfully opened\n", adapter_name); /* * Housekeeping */ PFRING.set_application_name(adapter->ring, "masscan"); PFRING.version(adapter->ring, &version); LOG(1, "pfring: version %d.%d.%d\n", (version >> 16) & 0xFFFF, (version >> 8) & 0xFF, (version >> 0) & 0xFF); LOG(2, "pfring:'%s': setting direction\n", adapter_name); err = PFRING.set_direction(adapter->ring, rx_only_direction); if (err) { fprintf(stderr, "pfring:'%s': setdirection = %d\n", adapter_name, err); } else LOG(2, "pfring:'%s': direction success\n", adapter_name); /* * Activate * * PF_RING requires a separate activation step. */ LOG(2, "pfring:'%s': activating\n", adapter_name); err = PFRING.enable_ring(adapter->ring); if (err != 0) { LOG(0, "pfring: '%s': ENABLE ERROR: %s\n", adapter_name, strerror(errno)); PFRING.close(adapter->ring); adapter->ring = 0; return 0; } else LOG(1, "pfring:'%s': successfully enabled\n", adapter_name); return adapter; } /*---------------------------------------------------------------- * Kludge: for using files *----------------------------------------------------------------*/ if (memcmp(adapter_name, "file:", 5) == 0) { LOG(1, "pcap: file: %s\n", adapter_name+5); is_pcap_file = 1; adapter->pcap = PCAP.open_offline(adapter_name+5, errbuf); adapter->link_type = PCAP.datalink(adapter->pcap); } /*---------------------------------------------------------------- * PORTABILITY: LIBPCAP * * This is the standard that should work everywhere. *----------------------------------------------------------------*/ { int err; LOG(1, "[+] if(%s): pcap: %s\n", adapter_name, PCAP.lib_version()); LOG(2, "[+] if(%s): opening...\n", adapter_name); /* This reserves resources, but doesn't actually open the * adapter until we call pcap_activate */ adapter->pcap = PCAP.create(adapter_name, errbuf); if (adapter->pcap == NULL) { adapter->pcap = PCAP.open_live( adapter_name, /* interface name */ 65536, /* max packet size */ 8, /* promiscuous mode */ 1000, /* read timeout in milliseconds */ errbuf); if (adapter->pcap == NULL) { LOG(0, "FAIL:%s: can't open adapter: %s\n", adapter_name, errbuf); if (strstr(errbuf, "perm")) { LOG(0, "FAIL: permission denied\n"); LOG(0, " [hint] need to sudo or run as root or something\n"); } return 0; } } else { err = PCAP.set_snaplen(adapter->pcap, 65536); if (err) { PCAP.perror(adapter->pcap, "if: set_snaplen"); goto pcap_error; } err = PCAP.set_promisc(adapter->pcap, 8); if (err) { PCAP.perror(adapter->pcap, "if: set_promisc"); goto pcap_error; } err = PCAP.set_timeout(adapter->pcap, 1000); if (err) { PCAP.perror(adapter->pcap, "if: set_timeout"); goto pcap_error; } err = PCAP.set_immediate_mode(adapter->pcap, 1); if (err) { PCAP.perror(adapter->pcap, "if: set_immediate_mode"); goto pcap_error; } /* If errors happen, they aren't likely to happen above, but will * happen where when they are applied */ err = PCAP.activate(adapter->pcap); switch (err) { case 0: /* drop down below */ break; case PCAP_ERROR_PERM_DENIED: LOG(0, "[-] FAIL: permission denied\n"); LOG(0, " [hint] need to sudo or run as root or something\n"); goto pcap_error; default: LOG(0, "[-] if(%s): activate:%d: %s\n", adapter_name, err, PCAP.geterr(adapter->pcap)); if (err < 0) goto pcap_error; } } LOG(1, "[+] if(%s): successfully opened\n", adapter_name); /* Figure out the link-type. We suport Ethernet and IP */ adapter->link_type = PCAP.datalink(adapter->pcap); switch (adapter->link_type) { case -1: PCAP.perror(adapter->pcap, "if: datalink"); goto pcap_error; case 0: /* Null/Loopback [VPN tunnel] */ LOG(1, "[+] if(%s): VPN tunnel interface found\n", adapter_name); break; case 1: /* Ethernet */ case 12: /* IP Raw */ break; default: LOG(0, "[-] if(%s): unknown data link type: %u(%s)\n", adapter_name, adapter->link_type, PCAP.datalink_val_to_name(adapter->link_type)); break; } } /*---------------------------------------------------------------- * PORTABILITY: WINDOWS * * The transmit rate on Windows is really slow, like 40-kpps. * The speed can be increased by using the "sendqueue" feature * to roughly 300-kpps. *----------------------------------------------------------------*/ adapter->sendq = 0; #if defined(WIN32) if (is_sendq) adapter->sendq = PCAP.sendqueue_alloc(SENDQ_SIZE); #endif return adapter; pcap_error: if (adapter->pcap) { PCAP.close(adapter->pcap); adapter->pcap = NULL; } if (adapter->pcap == NULL) { if (strcmp(adapter_name, "vmnet1") == 0) { LOG(0, " [hint] VMware on Macintosh doesn't support masscan\n"); } return 0; } return NULL; } /*************************************************************************** * for testing when two Windows adapters have the same name. Sometimes * the \Device\NPF_ string is prepended, sometimes not. ***************************************************************************/ int rawsock_is_adapter_names_equal(const char *lhs, const char *rhs) { if (memcmp(lhs, "\\Device\\NPF_", 12) == 0) lhs += 12; if (memcmp(rhs, "\\Device\\NPF_", 12) == 0) rhs += 12; return strcmp(lhs, rhs) == 0; } /*************************************************************************** * Runs some tests when the "--debug if" option is given on the * command-line. This is useful to figure out why the interface you * are accessing doesn't work. ***************************************************************************/ int rawsock_selftest_if(const char *ifname) { int err; ipv4address_t ipv4 = 0; ipv6address_t ipv6; ipv4address_t router_ipv4 = 0; macaddress_t source_mac = {{0,0,0,0,0,0}}; struct Adapter *adapter; char ifname2[246]; ipaddress_formatted_t fmt; /* * Get the interface */ if (ifname == NULL || ifname[0] == 0) { err = rawsock_get_default_interface(ifname2, sizeof(ifname2)); if (err) { printf("[-] if = not found (err=%d)\n", err); return -1; } ifname = ifname2; } printf("[+] if = %s\n", ifname); /* * Initialize the adapter. */ adapter = rawsock_init_adapter(ifname, 0, 0, 0, 0, 0, 0, 0); if (adapter == 0) { printf("[-] pcap = failed\n"); return -1; } else { printf("[+] pcap = opened\n"); } /* IPv4 address */ ipv4 = rawsock_get_adapter_ip(ifname); if (ipv4 == 0) { printf("[-] source-ipv4 = not found (err)\n"); } else { fmt = ipv4address_fmt(ipv4); printf("[+] source-ipv4 = %s\n", fmt.string); } /* IPv6 address */ ipv6 = rawsock_get_adapter_ipv6(ifname); if (ipv6address_is_zero(ipv6)) { printf("[-] source-ipv6 = not found\n"); } else { fmt = ipv6address_fmt(ipv6); printf("[+] source-ipv6 = [%s]\n", fmt.string); } /* MAC address */ err = rawsock_get_adapter_mac(ifname, source_mac.addr); if (err) { printf("[-] source-mac = not found (err=%d)\n", err); } else { fmt = macaddress_fmt(source_mac); printf("[+] source-mac = %s\n", fmt.string); } switch (adapter->link_type) { case 0: printf("[+] router-ip = implicit\n"); printf("[+] router-mac = implicit\n"); break; default: /* IPv4 router IP address */ err = rawsock_get_default_gateway(ifname, &router_ipv4); if (err) { fprintf(stderr, "[-] router-ip = not found(err=%d)\n", err); } else { fmt = ipv4address_fmt(router_ipv4); printf("[+] router-ip = %s\n", fmt.string); } /* IPv4 router MAC address */ { macaddress_t router_mac = {{0,0,0,0,0,0}}; stack_arp_resolve( adapter, ipv4, source_mac, router_ipv4, &router_mac); if (macaddress_is_zero(router_mac)) { printf("[-] router-mac-ipv4 = not found\n"); } else { fmt = macaddress_fmt(router_mac); printf("[+] router-mac-ipv4 = %s\n", fmt.string); } } /* * IPv6 router MAC address. * If it's not configured, then we need to send a (synchronous) query * to the network in order to discover the location of routers on * the local network */ if (!ipv6address_is_zero(ipv6)) { macaddress_t router_mac = {{0,0,0,0,0,0}}; stack_ndpv6_resolve( adapter, ipv6, source_mac, &router_mac); if (macaddress_is_zero(router_mac)) { printf("[-] router-mac-ipv6 = not found\n"); } else { fmt = macaddress_fmt(router_mac); printf("[+] router-mac-ipv6 = %s\n", fmt.string); } } } rawsock_close_adapter(adapter); return 0; } /*************************************************************************** ***************************************************************************/ int rawsock_selftest() { return 0; }
31,197
C
.c
859
28.018626
123
0.495236
robertdavidgraham/masscan
23,250
3,042
399
AGPL-3.0
9/7/2024, 9:40:14 AM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
5,340
main-dedup.c
robertdavidgraham_masscan/src/main-dedup.c
/* Filters duplicate responses This is an asynchronous and "stateless" scanner that spews out probes without having holding "state" for the probes. This means that when a response comes back, we have no "state" to associate with it. This means when two responses come back, we still don't have any "state" to remember that the first one came back. This will cause us to report two results instead of one. We could create a large table holding a record for EVERY response that we've seen. But this would require a lot of memory for large scans. Instead, we remember a small hashtable of recent responses. This takes advantage of the fact that multiple responses are likely to be recent and eventually age out. We call this "deduplication" as it's simply removing duplicate responses. */ #include "main-dedup.h" #include "util-malloc.h" #include <stdlib.h> #include <string.h> #include <assert.h> #include "syn-cookie.h" /** * This is the number of entries in our table. More entries does a better job at the * cost of using more memory. */ #define DEDUP_ENTRIES 65536 struct DedupEntry_IPv4 { unsigned ip_them; unsigned port_them; unsigned ip_me; unsigned port_me; }; struct DedupEntry_IPv6 { ipv6address ip_them; ipv6address ip_me; unsigned short port_them; unsigned short port_me; }; /** * This is simply the array of entries. We have two arrays, one for IPv4 * and another for IPv6. */ struct DedupTable { struct DedupEntry_IPv4 entries[DEDUP_ENTRIES][4]; struct DedupEntry_IPv6 entries6[DEDUP_ENTRIES][4]; }; /** * We use the FNv1a hash algorithm, which starts with this seed value. */ const unsigned fnv1a_seed = 0x811C9DC5; /* 2166136261 */ /** * Hash one byte, the other hash functions of multiple bytes call this function. * @param hash * The current hash value that we keep updating as we repeatedly * call this function, or the `fnv1a_seed value on the first call to * this function. */ static inline unsigned fnv1a(unsigned char c, unsigned hash) { const unsigned prime = 0x01000193; /* 16777619 */ return (c ^ hash) * prime; } static unsigned fnv1a_string(const void *v_buf, size_t length, unsigned hash) { const unsigned char *buf = (const unsigned char *)v_buf; size_t i; for (i=0; i<length; i++) hash = fnv1a(buf[i], hash); return hash; } static inline unsigned fnv1a_short(unsigned data, unsigned hash) { hash = fnv1a((data>>0)&0xFF, hash); hash = fnv1a((data>>8)&0xFF, hash); return hash; } static inline unsigned fnv1a_longlong(unsigned long long data, unsigned hash) { return fnv1a_string(&data, 8, hash); } /** * Create a new table, which means simply allocating the object * and setting it to zero. */ struct DedupTable * dedup_create(void) { struct DedupTable *dedup; dedup = CALLOC(1, sizeof(*dedup)); return dedup; } /** * There's nothing special we need to do to free the structure * since it's all contained in the single allocation. */ void dedup_destroy(struct DedupTable *dedup) { free(dedup); } /** * Create a hash of the IPv6 socket. This doesn't have to be * cryptographically secure, so we are going to use the FNv1a algorithm. */ static inline unsigned dedup_hash_ipv6(ipaddress ip_them, unsigned port_them, ipaddress ip_me, unsigned port_me) { unsigned hash = fnv1a_seed; hash = fnv1a_longlong(ip_them.ipv6.hi, hash); hash = fnv1a_longlong(ip_them.ipv6.lo, hash); hash = fnv1a_short(port_them, hash); hash = fnv1a_longlong(ip_me.ipv6.hi, hash); hash = fnv1a_longlong(ip_me.ipv6.lo, hash); hash = fnv1a_short(port_me, hash); return hash; } /** * If two IPv6 addresses are equal. */ static inline int is_equal6(ipv6address lhs, ipv6address rhs) { return lhs.hi == rhs.hi && lhs.lo == rhs.lo; } /** * Swap two addresses in the table. This uses the classic XOR trick * rather than using a swap variable. */ static inline void swap6(struct DedupEntry_IPv6 *lhs, struct DedupEntry_IPv6 *rhs) { lhs->ip_them.hi ^= rhs->ip_them.hi; lhs->ip_them.lo ^= rhs->ip_them.lo; lhs->port_them ^= rhs->port_them; lhs->ip_me.hi ^= rhs->ip_me.hi; lhs->ip_me.lo ^= rhs->ip_me.lo; lhs->port_me ^= rhs->port_me; rhs->ip_them.hi ^= lhs->ip_them.hi; rhs->ip_them.lo ^= lhs->ip_them.lo; rhs->port_them ^= lhs->port_them; rhs->ip_me.hi ^= lhs->ip_me.hi; rhs->ip_me.lo ^= lhs->ip_me.lo; rhs->port_me ^= lhs->port_me; lhs->ip_them.hi ^= rhs->ip_them.hi; lhs->ip_them.lo ^= rhs->ip_them.lo; lhs->port_them ^= rhs->port_them; lhs->ip_me.hi ^= rhs->ip_me.hi; lhs->ip_me.lo ^= rhs->ip_me.lo; lhs->port_me ^= rhs->port_me; } /** * This implements the same algorithm as for IPv4 addresses, but for * IPv6 addresses instead. */ static unsigned dedup_is_duplicate_ipv6(struct DedupTable *dedup, ipaddress ip_them, unsigned port_them, ipaddress ip_me, unsigned port_me) { unsigned hash; struct DedupEntry_IPv6 *bucket; unsigned i; /* THREAT: probably need to secure this hash, though the syn-cookies * provides some protection */ hash = dedup_hash_ipv6(ip_them, port_them, ip_me, port_me); hash &= DEDUP_ENTRIES-1; /* Search in this bucket */ bucket = dedup->entries6[hash]; /* If we find the entry in our table, move it to the front, so * that it won't be aged out as quickly. We keep prepending new * addresses to front, aging older addresses that haven't been * seen in a while. */ for (i = 0; i < 4; i++) { if (is_equal6(bucket[i].ip_them, ip_them.ipv6) && bucket[i].port_them == port_them && is_equal6(bucket[i].ip_me, ip_me.ipv6) && bucket[i].port_me == port_me) { /* move to end of list so constant repeats get ignored */ if (i > 0) { swap6(&bucket[0], &bucket[i]); } return 1; } } /* We didn't find it, so add it to our list. This will push * older entries at this bucket off the list */ memmove(bucket, bucket+1, 3*sizeof(*bucket)); bucket[0].ip_them.hi = ip_them.ipv6.hi; bucket[0].ip_them.lo = ip_them.ipv6.lo; bucket[0].port_them = (unsigned short)port_them; bucket[0].ip_me.hi = ip_me.ipv6.hi; bucket[0].ip_me.lo = ip_me.ipv6.lo; bucket[0].port_me = (unsigned short)port_me; return 0; } /*************************************************************************** ***************************************************************************/ static unsigned dedup_is_duplicate_ipv4(struct DedupTable *dedup, ipaddress ip_them, unsigned port_them, ipaddress ip_me, unsigned port_me) { unsigned hash; struct DedupEntry_IPv4 *bucket; unsigned i; /* THREAT: probably need to secure this hash, though the syn-cookies * provides some protection */ hash = (ip_them.ipv4 + port_them) ^ ((ip_me.ipv4) + (ip_them.ipv4>>16)) ^ (ip_them.ipv4>>24) ^ port_me; hash &= DEDUP_ENTRIES-1; /* Search in this bucket */ bucket = dedup->entries[hash]; /* If we find the entry in our table, move it to the front, so * that it won't be aged out as quickly. We keep prepending new * addresses to front, aging older addresses that haven't been * seen in a while. */ for (i = 0; i < 4; i++) { if (bucket[i].ip_them == ip_them.ipv4 && bucket[i].port_them == port_them && bucket[i].ip_me == ip_me.ipv4 && bucket[i].port_me == port_me) { /* move to end of list so constant repeats get ignored */ if (i > 0) { bucket[i].ip_them ^= bucket[0].ip_them; bucket[i].port_them ^= bucket[0].port_them; bucket[i].ip_me ^= bucket[0].ip_me; bucket[i].port_me ^= bucket[0].port_me; bucket[0].ip_them ^= bucket[i].ip_them; bucket[0].port_them ^= bucket[i].port_them; bucket[0].ip_me ^= bucket[i].ip_me; bucket[0].port_me ^= bucket[i].port_me; bucket[i].ip_them ^= bucket[0].ip_them; bucket[i].port_them ^= bucket[0].port_them; bucket[i].ip_me ^= bucket[0].ip_me; bucket[i].port_me ^= bucket[0].port_me; } return 1; } } /* We didn't find it, so add it to our list. This will push * older entries at this bucket off the list */ memmove(bucket, bucket+1, 3*sizeof(*bucket)); bucket[0].ip_them = ip_them.ipv4; bucket[0].port_them = port_them; bucket[0].ip_me = ip_me.ipv4; bucket[0].port_me = port_me; return 0; } /*************************************************************************** ***************************************************************************/ unsigned dedup_is_duplicate(struct DedupTable *dedup, ipaddress ip_them, unsigned port_them, ipaddress ip_me, unsigned port_me) { if (ip_them.version == 6) return dedup_is_duplicate_ipv6(dedup, ip_them, port_them, ip_me, port_me); else return dedup_is_duplicate_ipv4(dedup, ip_them, port_them, ip_me, port_me); } /** * My own deterministic rand() function for testing this module */ static unsigned _rand(unsigned *seed) { static const unsigned a = 214013; static const unsigned c = 2531011; *seed = (*seed) * a + c; return (*seed)>>16 & 0x7fff; } /* * Provide a simple unit test for this module. * * This is a pretty lame test. I'm going to generate * a set of random addresses, tweaked so that they aren't * too random, so that I get around 30 to 50 expected * duplicates. If I get zero duplicates, or if I get too * many duplicates in the test, then I know it's failed. * * This is in no way a reliable test that deterministically * tests the functionality. It's a crappy non-deterministic * test. * * We also do a simple deterministic test, but this still * is insufficient testing how duplicates age out and such. */ int dedup_selftest(void) { struct DedupTable *dedup; unsigned seed = 0; size_t i; unsigned found_match = 0; unsigned line = 0; dedup = dedup_create(); /* Deterministic test. * * The first time we check on a socket combo, there should * be no duplicate. The second time we check, however, there should * be a duplicate. */ { ipaddress ip_me; ipaddress ip_them; unsigned port_me; unsigned port_them; ip_me.version = 4; ip_them.version = 4; ip_me.ipv4 = 0x12345678; ip_them.ipv4 = 0xabcdef0; port_me = 0x1234; port_them = 0xfedc; if (dedup_is_duplicate(dedup, ip_them, port_them, ip_me, port_me)) { line = __LINE__; goto fail; } if (!dedup_is_duplicate(dedup, ip_them, port_them, ip_me, port_me)) { line = __LINE__; goto fail; } ip_me.version = 6; ip_them.version = 6; ip_me.ipv6.hi = 0x12345678; ip_me.ipv6.lo = 0x12345678; ip_them.ipv6.hi = 0xabcdef0; ip_them.ipv6.lo = 0xabcdef0; if (dedup_is_duplicate(dedup, ip_them, port_them, ip_me, port_me)) { line = __LINE__; goto fail; } if (!dedup_is_duplicate(dedup, ip_them, port_them, ip_me, port_me)) { ipaddress_formatted_t fmt1 = ipaddress_fmt(ip_them); ipaddress_formatted_t fmt2 = ipaddress_fmt(ip_me); fprintf(stderr, "[-] [%s]:%u -> [%s]:%u\n", fmt1.string, port_them, fmt2.string, port_me); line = __LINE__; goto fail; } } /* Test IPv4 addresses */ for (i=0; i<100000; i++) { ipaddress ip_me; ipaddress ip_them; unsigned port_me; unsigned port_them; ip_me.version = 4; ip_them.version = 4; /* Instead of completely random numbers over the entire * range, each port/IP is restricted to just 512 * random combinations. This should statistically * give us around 10 matches*/ ip_me.ipv4 = _rand(&seed) & 0xFF800000; ip_them.ipv4 = _rand(&seed) & 0x1FF; port_me = _rand(&seed) & 0xFF80; port_them = _rand(&seed) & 0x1FF; if (dedup_is_duplicate(dedup, ip_them, port_them, ip_me, port_me)) { found_match++; } } /* Approximately 30 matches should be found. If we couldn't * find any, or if we've found too many, then the test has * failed. */ if (found_match == 0 || found_match > 200) { line = __LINE__; goto fail; } /* Now do IPv6 */ found_match = 0; seed = 0; /* Test IPv4 addresses */ for (i=0; i<100000; i++) { ipaddress ip_me; ipaddress ip_them; unsigned port_me; unsigned port_them; ip_me.version = 6; ip_them.version = 6; /* Instead of completely random numbers over the entire * range, each port/IP is restricted to just 512 * random combinations. This should statistically * give us around 10 matches*/ ip_me.ipv6.hi = _rand(&seed) & 0xFF800000; ip_them.ipv6.lo = _rand(&seed) & 0x1FF; port_me = _rand(&seed) & 0xFF80; port_them = _rand(&seed) & 0x1FF; if (dedup_is_duplicate(dedup, ip_them, port_them, ip_me, port_me)) { found_match++; } } /* The result should be same as for IPv4, around 30 matches found. */ if (found_match == 0 || found_match > 200) { line = __LINE__; goto fail; } /* All tests have passed */ return 0; /* success :) */ fail: fprintf(stderr, "[-] selftest: 'dedup' failed, file=%s, line=%u\n", __FILE__, line); return 1; }
14,078
C
.c
402
29.017413
107
0.609481
robertdavidgraham/masscan
23,250
3,042
399
AGPL-3.0
9/7/2024, 9:40:14 AM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
5,342
proto-mc.c
robertdavidgraham_masscan/src/proto-mc.c
#include "proto-mc.h" #include "proto-banner1.h" #include "unusedparm.h" #include "masscan-app.h" #include "stack-tcp-api.h" #include "output.h" #include <ctype.h> #include <string.h> #include <stdlib.h> static unsigned char hand_shake_ptr[128]; static unsigned char * hand_shake(uint16_t port, const char* ip, size_t ip_len) { size_t tlen = 10+ip_len; unsigned char * ret = (unsigned char *)calloc(1,tlen); ret[0] = (unsigned char)(7+ip_len); ret[2] = 0xf7; ret[3] = 5; ret[4] = (unsigned char)ip_len; memcpy(ret+5,ip,ip_len); ret[tlen-5] = (unsigned char)(port>>8); ret[tlen-4] = (unsigned char)(port&0xff); ret[tlen-3] = 1; ret[tlen-2] = 1; ret[tlen-1] = 0; return ret; } static void * memstr(void * mem, size_t len, char * str) { size_t i; size_t stlen = strlen(str); if(len < stlen) return 0; for(i = 0; i < len-stlen; i++) { if(!memcmp((char*)mem+i,str,stlen)) return (char*)mem+i; } return 0; } /*************************************************************************** ***************************************************************************/ static void mc_parse( const struct Banner1 *banner1, void *banner1_private, struct StreamState *pstate, const unsigned char *px, size_t length, struct BannerOutput *banout, struct stack_handle_t *socket) { size_t i; struct MCSTUFF *mc = &pstate->sub.mc; UNUSEDPARM(banner1_private); UNUSEDPARM(banner1); for(i = 0; i < length; i++) { if(px[i] == '{') mc->brackcount++; if(px[i] == '}') mc->brackcount--; } if(mc->brackcount <= 0) tcpapi_close(socket); if((mc->imgstart&&mc->imgend) || mc->brackcount <= 0) { // we already found and removed image data banout_append(banout, PROTO_MC,px,length); } else { mc->banmem = realloc(mc->banmem,mc->totalLen+length+1); // expand to add new memory for added paket memcpy(mc->banmem+mc->totalLen,px,length); // copy in new packet mc->banmem[mc->totalLen] = 0; // add ending 0 for str mc->totalLen+=length; if(!mc->imgstart) { // dont search again if we found start mc->imgstart = (size_t)memstr(mc->banmem,mc->totalLen,"data:image/png;base64"); if(mc->imgstart) mc->imgstart-=(size_t)mc->banmem; } else { // we found start but not the end mc->imgend = (size_t)memchr(mc->banmem+mc->imgstart,'\"',mc->totalLen-mc->imgstart); if(mc->imgend){ // we found the end mc->imgend-=(size_t)mc->banmem; memcpy(mc->banmem+mc->imgstart,mc->banmem+mc->imgend,(mc->totalLen-mc->imgend)+1); // copy data after B64 mc->totalLen=mc->imgstart+(mc->totalLen-mc->imgend); // shrink length to subtract B64 image banout_append(banout, PROTO_MC,mc->banmem,mc->totalLen); // print out banner minus image data free(mc->banmem); // we dont need to keep track of this any more. } } } } /*************************************************************************** ***************************************************************************/ static void * mc_init(struct Banner1 *banner1) { unsigned char * tmp = hand_shake(25565,"localhost",9); memcpy(hand_shake_ptr,tmp,tmp[0]+3); free(tmp); banner_mc.hello = hand_shake_ptr; banner_mc.hello_length = hand_shake_ptr[0]+3; banner1->payloads.tcp[25565] = (void*)&banner_mc; return 0; } /*************************************************************************** ***************************************************************************/ static int mc_selftest(void) { return 0; } /*************************************************************************** ***************************************************************************/ struct ProtocolParserStream banner_mc = { "mc", 25565, 0, 0, 0, mc_selftest, mc_init, mc_parse, };
4,073
C
.c
113
30.424779
121
0.507844
robertdavidgraham/masscan
23,250
3,042
399
AGPL-3.0
9/7/2024, 9:40:14 AM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
5,343
proto-coap.h
robertdavidgraham_masscan/src/proto-coap.h
#ifndef PROTO_COAP_H #define PROTO_COAP_H #include "proto-banner1.h" struct Output; struct PreprocessedInfo; /* * For sending TCP requests and parsing TCP responses. */ extern const struct ProtocolParserStream banner_coap; /* * For parsing UDP responses */ unsigned coap_handle_response(struct Output *out, time_t timestamp, const unsigned char *px, unsigned length, struct PreprocessedInfo *parsed, uint64_t entropy ); /* * For creating UDP request */ unsigned coap_udp_set_cookie(unsigned char *px, size_t length, uint64_t seqno); int proto_coap_selftest(void); #endif
631
C
.c
26
20.961538
70
0.731667
robertdavidgraham/masscan
23,250
3,042
399
AGPL-3.0
9/7/2024, 9:40:14 AM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
5,346
stack-arpv4.h
robertdavidgraham_masscan/src/stack-arpv4.h
#ifndef STACK_ARP_H #define STACK_ARP_H struct Adapter; #include "stack-queue.h" #include "massip-addr.h" /** * Response to an ARP request for our IP address. * * @param my_ip * My IP address * @param my_mac * My Ethernet MAC address that matches this IP address. * @param px * The incoming ARP request * @param length * The length of the incoming ARP request. * @param packet_buffers * Free packet buffers I can use to format the request * @param transmit_queue * I put the formatted response onto this queue for later * transmission by a transmit thread. */ int stack_arp_incoming_request(struct stack_t *stack, ipv4address_t my_ip, macaddress_t my_mac, const unsigned char *px, unsigned length); /** * Send an ARP request in order to resolve an IPv4 address into a * MAC address. Usually done in order to find the local router's * MAC address when given the IPv4 address of the router. */ int stack_arp_resolve(struct Adapter *adapter, ipv4address_t my_ipv4, macaddress_t my_mac_address, ipv4address_t your_ipv4, macaddress_t *your_mac_address); #endif
1,139
C
.c
34
31.088235
65
0.719601
robertdavidgraham/masscan
23,250
3,042
399
AGPL-3.0
9/7/2024, 9:40:14 AM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
5,348
stack-ndpv6.h
robertdavidgraham_masscan/src/stack-ndpv6.h
/* IPv6 Neighbor Discovery Protocol This module is needed to talk to the local IPv6 router. It does two things: 1. find the local router, so that we can send packets to it 2. response to Neighbor Discovery Requests, to the router can find us */ #ifndef STACK_NDPV6_H #define STACK_NDPV6_H #include <stddef.h> #include <time.h> #include "stack-queue.h" #include "massip-addr.h" struct PreprocessedInfo; /** * Handle an incoming IPv6 neighbor notification request. We must send * back our MAC address. */ int stack_ndpv6_incoming_request(struct stack_t *stack, struct PreprocessedInfo *parsed, const unsigned char *px, size_t length); /** * Find the MAC address for the local router. */ int stack_ndpv6_resolve(struct Adapter *adapter, ipv6address my_ipv6, macaddress_t my_mac_address, macaddress_t *your_mac_address); #endif
885
C
.c
31
25.612903
126
0.742317
robertdavidgraham/masscan
23,250
3,042
399
AGPL-3.0
9/7/2024, 9:40:14 AM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
5,350
stack-queue.h
robertdavidgraham_masscan/src/stack-queue.h
#ifndef PACKET_QUEUE_H #define PACKET_QUEUE_H #include "rte-ring.h" #include "massip-addr.h" #include <limits.h> struct stack_src_t; struct Adapter; typedef struct rte_ring PACKET_QUEUE; struct PacketBuffer { size_t length; unsigned char px[2040]; }; struct stack_t { PACKET_QUEUE *packet_buffers; PACKET_QUEUE *transmit_queue; macaddress_t source_mac; struct stack_src_t *src; }; /** * Get a packet-buffer that we can use to create a packet before * sending */ struct PacketBuffer * stack_get_packetbuffer(struct stack_t *stack); /** * Queue up the packet for sending. This doesn't send the packet immediately, * but puts it into a queue to be sent later, when the throttler allows it * to be sent. */ void stack_transmit_packetbuffer(struct stack_t *stack, struct PacketBuffer *response); void stack_flush_packets( struct stack_t *stack, struct Adapter *adapter, uint64_t *packets_sent, uint64_t *batchsize); struct stack_t * stack_create(macaddress_t source_mac, struct stack_src_t *src); #endif
1,054
C
.c
40
23.975
82
0.747515
robertdavidgraham/masscan
23,250
3,042
399
AGPL-3.0
9/7/2024, 9:40:14 AM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
5,353
proto-tcp-rdp.h
robertdavidgraham_masscan/src/proto-tcp-rdp.h
#ifndef PROTO_TCP_RDP_H #define PROTO_TCP_RDP_H #include "proto-banner1.h" extern const struct ProtocolParserStream banner_rdp; #endif
138
C
.c
5
26
52
0.823077
robertdavidgraham/masscan
23,250
3,042
399
AGPL-3.0
9/7/2024, 9:40:14 AM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
5,354
massip-addr.c
robertdavidgraham_masscan/src/massip-addr.c
#include "massip-addr.h" #include <string.h> /** * Holds the output string, so that we can append to it without * overflowing buffers. The _append_xxx() functions below append * to this string. */ typedef struct stream_t { char *buf; size_t offset; size_t length; } stream_t; /** * Append a character to the output string. All the other _append_xxx() * functions call this one, so this is the only one where a * buffer-overflow can occur. */ static void _append_char(stream_t *out, char c) { if (out->offset < out->length) out->buf[out->offset++] = c; /* keep the string nul terminated as we build it */ if (out->offset < out->length) out->buf[out->offset] = '\0'; } static void _append_ipv6(stream_t *out, const unsigned char *ipv6) { static const char hex[] = "0123456789abcdef"; size_t i; int is_ellision = 0; /* An IPv6 address is printed as a series of 2-byte hex words * separated by colons :, for a total of 16-bytes */ for (i = 0; i < 16; i += 2) { unsigned n = ipv6[i] << 8 | ipv6[i + 1]; /* Handle the ellision case. A series of words with a value * of 0 can be removed completely, replaced by an extra colon */ if (n == 0 && !is_ellision) { is_ellision = 1; while (i < 13 && ipv6[i + 2] == 0 && ipv6[i + 3] == 0) i += 2; _append_char(out, ':'); /* test for all-zero address, in which case the output * will be "::". */ while (i == 14 && ipv6[i] == 0 && ipv6[i + 1] == 0){ i=16; _append_char(out, ':'); } continue; } /* Print the colon between numbers. Fence-post alert: only colons * between numbers are printed, not at the beginning or end of the * string */ if (i) _append_char(out, ':'); /* Print the digits. Leading zeroes are not printed */ if (n >> 12) _append_char(out, hex[(n >> 12) & 0xF]); if (n >> 8) _append_char(out, hex[(n >> 8) & 0xF]); if (n >> 4) _append_char(out, hex[(n >> 4) & 0xF]); _append_char(out, hex[(n >> 0) & 0xF]); } } struct ipaddress_formatted ipv6address_fmt(ipv6address a) { struct ipaddress_formatted out; unsigned char tmp[16]; size_t i; stream_t s; /* * Convert address into a sequence of bytes. Our code * here represents an IPv6 address as two 64-bit numbers, but * the formatting code above that we copied from a different * project represents it as an array of bytes. */ for (i=0; i<16; i++) { uint64_t x; if (i<8) x = a.hi; else x = a.lo; x >>= (7 - (i%8)) * 8; tmp[i] = (unsigned char)(x & 0xFF); } /* Call the formatting function */ s.buf = out.string; s.offset = 0; s.length = sizeof(out.string); _append_ipv6(&s, tmp); return out; } /** * Append a decimal integer. */ static void _append_decimal(stream_t *out, unsigned long long n) { char tmp[64]; size_t tmp_offset = 0; /* Create temporary string */ while (n >= 10) { unsigned digit = n % 10; n /= 10; tmp[tmp_offset++] = (char)('0' + digit); } /* the final digit, may be zero */ tmp[tmp_offset++] = (char)('0' + n); /* Copy the result backwards */ while (tmp_offset) _append_char(out, tmp[--tmp_offset]); } static void _append_hex2(stream_t *out, unsigned long long n) { static const char hex[17] = "0123456789abcdef"; _append_char(out, hex[(n>>4)&0xF]); _append_char(out, hex[(n>>0)&0xF]); } struct ipaddress_formatted ipv4address_fmt(ipv4address ip) { struct ipaddress_formatted out; stream_t s; /* Call the formatting function */ s.buf = out.string; s.offset = 0; s.length = sizeof(out.string); _append_decimal(&s, (ip >> 24) & 0xFF); _append_char(&s, '.'); _append_decimal(&s, (ip >> 16) & 0xFF); _append_char(&s, '.'); _append_decimal(&s, (ip >> 8) & 0xFF); _append_char(&s, '.'); _append_decimal(&s, (ip >> 0) & 0xFF); return out; } struct ipaddress_formatted macaddress_fmt(macaddress_t mac) { struct ipaddress_formatted out; stream_t s; /* Call the formatting function */ s.buf = out.string; s.offset = 0; s.length = sizeof(out.string); _append_hex2(&s, mac.addr[0]); _append_char(&s, '-'); _append_hex2(&s, mac.addr[1]); _append_char(&s, '-'); _append_hex2(&s, mac.addr[2]); _append_char(&s, '-'); _append_hex2(&s, mac.addr[3]); _append_char(&s, '-'); _append_hex2(&s, mac.addr[4]); _append_char(&s, '-'); _append_hex2(&s, mac.addr[5]); return out; } struct ipaddress_formatted ipaddress_fmt(ipaddress a) { struct ipaddress_formatted out; stream_t s; ipv4address ip = a.ipv4; if (a.version == 6) { return ipv6address_fmt(a.ipv6); } /* Call the formatting function */ s.buf = out.string; s.offset = 0; s.length = sizeof(out.string); _append_decimal(&s, (ip >> 24) & 0xFF); _append_char(&s, '.'); _append_decimal(&s, (ip >> 16) & 0xFF); _append_char(&s, '.'); _append_decimal(&s, (ip >> 8) & 0xFF); _append_char(&s, '.'); _append_decimal(&s, (ip >> 0) & 0xFF); return out; } static unsigned _count_long(uint64_t number) { unsigned i; unsigned count = 0; for (i=0; i<64; i++) { if ((number >> i) & 1) count = i + 1; } return count; } /** * Find the number of bits needed to hold the integer. In other words, * the number 0x64 would need 7 bits to store it. * * We use this to count the size of scans. We currently only support * scan sizes up to 63 bits. */ unsigned massint128_bitcount(massint128_t number) { if (number.hi) return _count_long(number.hi) + 64; else return _count_long(number.lo); } ipv6address_t ipv6address_add_uint64(ipv6address_t lhs, uint64_t rhs) { lhs.lo += rhs; if (lhs.lo < rhs) { lhs.hi += 1; } return lhs; } ipv6address_t ipv6address_subtract(ipv6address_t lhs, ipv6address_t rhs) { ipv6address_t difference; difference.hi = lhs.hi - rhs.hi; difference.lo = lhs.lo - rhs.lo; /* check for underflow */ if (difference.lo > lhs.lo) difference.hi -= 1; return difference; } ipv6address_t ipv6address_add(ipv6address_t lhs, ipv6address_t rhs) { ipv6address_t sum; sum.hi = lhs.hi + rhs.hi; sum.lo = lhs.lo - rhs.lo; /* check for underflow */ if (sum.lo > lhs.lo) sum.hi += 1; return sum; } int ipv6address_selftest(void) { int x = 0; ipaddress ip; struct ipaddress_formatted fmt; ip.version = 4; ip.ipv4 = 0x01FF00A3; fmt = ipaddress_fmt(ip); if (strcmp(fmt.string, "1.255.0.163") != 0) x++; return x; } int ipv6address_is_equal_prefixed(ipv6address_t lhs, ipv6address_t rhs, unsigned prefix) { ipv6address mask; /* If the prefix is bad, then the answer is 'no'. */ if (prefix > 128) { return 0; } /* Create the mask from the prefix */ if (prefix > 64) mask.hi = ~0ULL; else if (prefix == 0) mask.hi = 0; else mask.hi = ~0ULL << (64 - prefix); if (prefix > 64) mask.lo = ~0ULL << (128 - prefix); else mask.lo = 0; /* Mask off any non-zero bits from both addresses */ lhs.hi &= mask.hi; lhs.lo &= mask.lo; rhs.hi &= mask.hi; rhs.lo &= mask.lo; /* Now do a normal compare */ return ipv6address_is_equal(lhs, rhs); }
7,748
C
.c
267
23.535581
88
0.578003
robertdavidgraham/masscan
23,250
3,042
399
AGPL-3.0
9/7/2024, 9:40:14 AM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
5,357
out-tcp-services.c
robertdavidgraham_masscan/src/out-tcp-services.c
#include "out-tcp-services.h" #include <string.h> #include <stdlib.h> #ifndef WIN32 #include <netdb.h> #else #include <WinSock2.h> #endif #include <ctype.h> /** * This is a stupid hack to avoid dependencies. I want to minimize the dependence * on network libraries. For example, I get a warning message on FreeBSD about * a missing `htons()`. I could just add a system header, but then this increases * dependencies on other things. Alternatively, I could just implement the * function myself. So I chose that route. */ static unsigned short my_htons(unsigned port) { static const char test[3] = "\x11\x22"; if (*(unsigned short*)test == 0x1122) return (unsigned short)(0xFFFF & port); else return (unsigned short)((port>>8)&0xFF) | ((port&0xFF)<<8); } #if _MSC_VER #define strdup _strdup #endif static char *tcp_services[65536]; static char *udp_services[65536]; static char *oproto_services[256]; const char * tcp_service_name(int port) { if (tcp_services[port]) return tcp_services[port]; #if defined(__linux__) && !defined(__TERMUX__) int r; struct servent result_buf; struct servent *result; char buf[2048]; r = getservbyport_r(my_htons(port), "tcp", &result_buf,buf, sizeof(buf), &result); /* ignore ERANGE - if the result can't fit in 2k, just return unknown */ if (r != 0 || result == NULL) return "unknown"; return tcp_services[port] = strdup(result_buf.s_name); #else { struct servent *result; result = getservbyport(my_htons((unsigned short)port), "tcp"); if (result == 0) return "unknown"; return tcp_services[port] = strdup(result->s_name); } #endif } const char * udp_service_name(int port) { if (udp_services[port]) return udp_services[port]; #if defined(__linux__) && !defined(__TERMUX__) int r; struct servent result_buf; struct servent *result; char buf[2048]; r = getservbyport_r(my_htons(port), "udp", &result_buf,buf, sizeof(buf), &result); /* ignore ERANGE - if the result can't fit in 2k, just return unknown */ if (r != 0 || result == NULL) return "unknown"; return udp_services[port] = strdup(result_buf.s_name); #else { struct servent *result; result = getservbyport(my_htons((unsigned short)port), "udp"); if (result == 0) return "unknown"; return udp_services[port] = strdup(result->s_name); } #endif } const char * oproto_service_name(int port) { if (oproto_services[port]) return oproto_services[port]; { struct protoent *result; result = getprotobynumber(port); if (result == 0) return "unknown"; return oproto_services[port] = strdup(result->p_name); } }
2,849
C
.c
93
25.741935
86
0.662406
robertdavidgraham/masscan
23,250
3,042
399
AGPL-3.0
9/7/2024, 9:40:14 AM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
5,365
templ-tcp-hdr.h
robertdavidgraham_masscan/src/templ-tcp-hdr.h
#ifndef TEMPL_TCP_H #define TEMPL_TCP_H #include "util-bool.h" /* <stdbool.h> */ #include <stdio.h> struct TemplateOptions; /** * Called during configuration, to apply all the various changes the * user asked for on the command-line, such as optioms like: * --tcp-mss 1460 * --tcp-sackperm * --tcp-wscale 3 */ void templ_tcp_apply_options(unsigned char **inout_buf, size_t *inout_length, const struct TemplateOptions *templ_opts); /** * Conduct a selftest of all the functions that manipulate the TCP * header template. */ int templ_tcp_selftest(void); #endif
590
C
.c
22
24.454545
72
0.723894
robertdavidgraham/masscan
23,250
3,042
399
AGPL-3.0
9/7/2024, 9:40:14 AM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
5,367
stack-tcp-core.h
robertdavidgraham_masscan/src/stack-tcp-core.h
#ifndef PROTO_TCP_H #define PROTO_TCP_H #include "massip-addr.h" #include "stack-queue.h" #include "output.h" #include "util-bool.h" struct Adapter; struct TCP_Control_Block; struct TemplatePacket; struct TCP_ConnectionTable; struct lua_State; struct ProtocolParserStream; #define TCP_SEQNO(px,i) (px[i+4]<<24|px[i+5]<<16|px[i+6]<<8|px[i+7]) #define TCP_ACKNO(px,i) (px[i+8]<<24|px[i+9]<<16|px[i+10]<<8|px[i+11]) #define TCP_FLAGS(px,i) (px[(i)+13]) #define TCP_IS_SYNACK(px,i) ((TCP_FLAGS(px,i) & 0x12) == 0x12) #define TCP_IS_ACK(px,i) ((TCP_FLAGS(px,i) & 0x10) == 0x10) #define TCP_IS_RST(px,i) ((TCP_FLAGS(px,i) & 0x4) == 0x4) #define TCP_IS_FIN(px,i) ((TCP_FLAGS(px,i) & 0x1) == 0x1) /** * [KLUDGE] The 'tcpcon' module doesn't have access to the main configuration, * so specific configuration options have to be sent to it using this * function. */ void tcpcon_set_parameter(struct TCP_ConnectionTable *tcpcon, const char *name, size_t value_length, const void *value); enum http_field_t { http_field_replace, http_field_add, http_field_remove, http_field_method, http_field_url, http_field_version, }; void tcpcon_set_http_header(struct TCP_ConnectionTable *tcpcon, const char *name, size_t value_length, const void *value, enum http_field_t what); void scripting_init_tcp(struct TCP_ConnectionTable *tcpcon, struct lua_State *L); /** * Create a TCP connection table (to store TCP control blocks) with * the desired initial size. * * @param entry_count * A hint about the desired initial size. This should be about twice * the number of outstanding connections, so you should base this number * on your transmit rate (the faster the transmit rate, the more * outstanding connections you'll have). This function will automatically * round this number up to the nearest power of 2, or round it down * if it causes malloc() to not be able to allocate enough memory. * @param entropy * Seed for syn-cookie randomization */ struct TCP_ConnectionTable * tcpcon_create_table( size_t entry_count, struct stack_t *stack, struct TemplatePacket *pkt_template, OUTPUT_REPORT_BANNER report_banner, struct Output *out, unsigned timeout, uint64_t entropy ); void tcpcon_set_banner_flags(struct TCP_ConnectionTable *tcpcon, unsigned is_capture_cert, unsigned is_capture_servername, unsigned is_capture_html, unsigned is_capture_heartbleed, unsigned is_capture_ticketbleed); /** * Gracefully destroy a TCP connection table. This is the last chance for any * partial banners (like HTTP server version) to be sent to the output. At the * end of a scan, you'll see a bunch of banners all at once due to this call. * * @param tcpcon * A TCP connection table created with a matching call to * 'tcpcon_create_table()'. */ void tcpcon_destroy_table(struct TCP_ConnectionTable *tcpcon); void tcpcon_timeouts(struct TCP_ConnectionTable *tcpcon, unsigned secs, unsigned usecs); enum TCP_What { TCP_WHAT_TIMEOUT, TCP_WHAT_SYNACK, TCP_WHAT_RST, TCP_WHAT_FIN, TCP_WHAT_ACK, TCP_WHAT_DATA, TCP_WHAT_CLOSE }; enum TCB_result { TCB__okay, TCB__destroyed }; enum TCB_result stack_incoming_tcp(struct TCP_ConnectionTable *tcpcon, struct TCP_Control_Block *entry, enum TCP_What what, const unsigned char *payload, size_t payload_length, unsigned secs, unsigned usecs, unsigned seqno_them, unsigned ackno_them); /** * Lookup a connection record based on IP/ports. */ struct TCP_Control_Block * tcpcon_lookup_tcb( struct TCP_ConnectionTable *tcpcon, ipaddress ip_src, ipaddress ip_dst, unsigned port_src, unsigned port_dst); /** * Create a new TCB (TCP control block. It's created only in two places, * either because we've initiated an outbound TCP connection, or we've * received incoming SYN-ACK from a probe. */ struct TCP_Control_Block * tcpcon_create_tcb( struct TCP_ConnectionTable *tcpcon, ipaddress ip_src, ipaddress ip_dst, unsigned port_src, unsigned port_dst, unsigned my_seqno, unsigned their_seqno, unsigned ttl, const struct ProtocolParserStream *stream, unsigned secs, unsigned usecs); void tcpcon_send_RST( struct TCP_ConnectionTable *tcpcon, ipaddress ip_me, ipaddress ip_them, unsigned port_me, unsigned port_them, uint32_t seqno_them, uint32_t ackno_them); /** * Send a reset packet back, even if we don't have a TCP connection * table */ void tcp_send_RST( struct TemplatePacket *templ, struct stack_t *stack, ipaddress ip_them, ipaddress ip_me, unsigned port_them, unsigned port_me, unsigned seqno_them, unsigned seqno_me ); #endif
5,080
C
.c
146
29.623288
87
0.677387
robertdavidgraham/masscan
23,250
3,042
399
AGPL-3.0
9/7/2024, 9:40:14 AM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
5,368
proto-vnc.c
robertdavidgraham_masscan/src/proto-vnc.c
#include "proto-vnc.h" #include "proto-banner1.h" #include "stack-tcp-api.h" #include "unusedparm.h" #include "masscan-app.h" #include "util-safefunc.h" #include "smack.h" #include <ctype.h> static void vnc_append_sectype(struct BannerOutput *banout, unsigned sectype) { char foo[16]; /* http://www.iana.org/assignments/rfb/rfb.xml Value Name Reference 0 Invalid [RFC6143] 1 None [RFC6143] 2 VNC Authentication [RFC6143] 3-15 RealVNC historic assignment 16 Tight historic assignment 17 Ultra historic assignment 18 TLS historic assignment 19 VeNCrypt historic assignment 20 GTK-VNC SASL historic assignment 21 MD5 hash authentication historic assignment 22 Colin Dean xvp historic assignment 23-29 Unassigned 30-35 Apple Inc. [Michael_Stein] 36-127 Unassigned 128-255 RealVNC historic assignment */ switch (sectype) { case 0: banout_append(banout, PROTO_VNC_INFO, " invalid", AUTO_LEN); break; case 1: banout_append(banout, PROTO_VNC_INFO, " none", AUTO_LEN); break; case 2: banout_append(banout, PROTO_VNC_INFO, " VNC-chap", AUTO_LEN); break; case 5: banout_append(banout, PROTO_VNC_INFO, " RA2", AUTO_LEN); break; case 6: banout_append(banout, PROTO_VNC_INFO, " RA2ne", AUTO_LEN); break; case 7: banout_append(banout, PROTO_VNC_INFO, " SSPI", AUTO_LEN); break; case 8: banout_append(banout, PROTO_VNC_INFO, " SSPIne", AUTO_LEN); break; case 16: banout_append(banout, PROTO_VNC_INFO, " Tight", AUTO_LEN); break; case 17: banout_append(banout, PROTO_VNC_INFO, " Ultra", AUTO_LEN); break; case 18: banout_append(banout, PROTO_VNC_INFO, " TLS", AUTO_LEN); break; case 19: banout_append(banout, PROTO_VNC_INFO, " VeNCrypt", AUTO_LEN); break; case 20: banout_append(banout, PROTO_VNC_INFO, " GTK-VNC-SASL", AUTO_LEN); break; case 21: banout_append(banout, PROTO_VNC_INFO, " MD5", AUTO_LEN); break; case 22: banout_append(banout, PROTO_VNC_INFO, " Colin-Dean-xvp", AUTO_LEN); break; case 30: banout_append(banout, PROTO_VNC_INFO, " Apple30", AUTO_LEN); break; case 35: banout_append(banout, PROTO_VNC_INFO, " Apple35", AUTO_LEN); break; default: snprintf(foo, sizeof(foo), " %u", sectype); banout_append(banout, PROTO_VNC_INFO, foo, AUTO_LEN); break; } } /*************************************************************************** ***************************************************************************/ static void vnc_parse( const struct Banner1 *banner1, void *banner1_private, struct StreamState *pstate, const unsigned char *px, size_t length, struct BannerOutput *banout, struct stack_handle_t *socket) { unsigned state = pstate->state; unsigned i; char foo[64]; enum { RFB3_3_SECURITYTYPES=50, RFB_SECURITYERROR=60, RFB3_7_SECURITYTYPES=100, RFB_SERVERINIT=200, RFB_SECURITYRESULT=300, RFB_DONE=0x7fffffff, }; UNUSEDPARM(banner1_private); UNUSEDPARM(banner1); for (i=0; i<length; i++) switch (state) { case 0: case 1: case 2: case 3: case 4: case 5: case 6: case 7: case 8: case 9: state++; banout_append_char(banout, PROTO_VNC_RFB, px[i]); break; case 10: state++; banout_append_char(banout, PROTO_VNC_RFB, px[i]); break; case 11: banout_append_char(banout, PROTO_VNC_RFB, px[i]); if ('\n' == px[i]) { static const char *response[] = { "RFB 003.003\n", "RFB 003.003\n", "RFB 003.003\n", "RFB 003.003\n", "RFB 003.003\n", "RFB 003.003\n", "RFB 003.003\n", "RFB 003.007\n", "RFB 003.008\n", "RFB 003.008\n", }; unsigned version = pstate->sub.vnc.version % 10; tcpapi_send(socket, response[version], 12, 0); if (version < 7) /* Version 3.3: the server selects either "none" or * "vnc challenge/response" and informs us which one * to use */ state = RFB3_3_SECURITYTYPES; else { /* Version 3.7 onwards: the server will send us a list * of security types it supports, from which the * client will select one */ state = RFB3_7_SECURITYTYPES; } } else { state = 0xFFFFFFFF; tcpapi_close(socket); } break; case RFB3_3_SECURITYTYPES: case RFB_SECURITYERROR: case RFB_SECURITYRESULT: case RFB_SERVERINIT+20: pstate->sub.vnc.sectype = px[i]; state++; break; case RFB3_3_SECURITYTYPES+1: case RFB3_3_SECURITYTYPES+2: case RFB_SECURITYERROR+1: case RFB_SECURITYERROR+2: case RFB_SECURITYRESULT+1: case RFB_SECURITYRESULT+2: case RFB_SERVERINIT+21: case RFB_SERVERINIT+22: pstate->sub.vnc.sectype <<= 8; pstate->sub.vnc.sectype |= px[i]; state++; break; case RFB3_3_SECURITYTYPES+3: pstate->sub.vnc.sectype <<= 8; pstate->sub.vnc.sectype |= px[i]; banout_append(banout, PROTO_VNC_INFO, "Security types:\n", AUTO_LEN); vnc_append_sectype(banout, pstate->sub.vnc.sectype); if (pstate->sub.vnc.sectype == 0) state = RFB_SECURITYERROR; else if (pstate->sub.vnc.sectype == 1) { /* v3.3 sectype=none * We move immediately to ClientInit stage */ tcpapi_send(socket, "\x01", 1, 0); state = RFB_SERVERINIT; } else { state = RFB_DONE; tcpapi_close(socket); } break; case RFB_SECURITYRESULT+3: pstate->sub.vnc.sectype <<= 8; pstate->sub.vnc.sectype |= px[i]; if (pstate->sub.vnc.sectype == 0) { /* security OK, move to client init */ tcpapi_send(socket, "\x01", 1, 0); state = RFB_SERVERINIT; } else { /* error occurred, so grab error message */ state = RFB_SECURITYERROR; } break; case RFB_SECURITYERROR+3: pstate->sub.vnc.sectype <<= 8; pstate->sub.vnc.sectype = px[i]; banout_append(banout, PROTO_VNC_INFO, "ERROR: ", AUTO_LEN); state++; break; case RFB_SECURITYERROR+4: if (pstate->sub.vnc.sectype == 0) { state = RFB_DONE; tcpapi_close(socket); } else { pstate->sub.vnc.sectype--; banout_append_char(banout, PROTO_VNC_INFO, px[i]); } break; case RFB3_7_SECURITYTYPES: pstate->sub.vnc.len = px[i]; if (pstate->sub.vnc.len == 0) state = RFB_SECURITYERROR; else { state++; banout_append(banout, PROTO_VNC_INFO, "Security types:\n", AUTO_LEN); } break; case RFB3_7_SECURITYTYPES+1: if (pstate->sub.vnc.len != 0) { pstate->sub.vnc.len--; vnc_append_sectype(banout, px[i]); } if (pstate->sub.vnc.len == 0) { banout_append(banout, PROTO_VNC_INFO, "\n", AUTO_LEN); if (pstate->sub.vnc.version < 7) { state = RFB_SERVERINIT; tcpapi_send(socket, "\x01", 1, 0); } else if (pstate->sub.vnc.version == 7) { state = RFB_SERVERINIT; tcpapi_send(socket, "\x01\x01", 2, 0); } else { state = RFB_SECURITYRESULT; tcpapi_send(socket, "\x01", 1, 0); } } else { banout_append(banout, PROTO_VNC_INFO, "\n", AUTO_LEN); } break; case RFB_SERVERINIT: pstate->sub.vnc.width = px[i]; state++; break; case RFB_SERVERINIT+1: pstate->sub.vnc.width <<= 8; pstate->sub.vnc.width |= px[i]; snprintf(foo, sizeof(foo), " width=%u", pstate->sub.vnc.width); banout_append(banout, PROTO_VNC_RFB, foo, AUTO_LEN); state++; break; case RFB_SERVERINIT+2: pstate->sub.vnc.height = px[i]; state++; break; case RFB_SERVERINIT+3: pstate->sub.vnc.height <<= 8; pstate->sub.vnc.height |= px[i]; snprintf(foo, sizeof(foo), " height=%u", pstate->sub.vnc.height); banout_append(banout, PROTO_VNC_RFB, foo, AUTO_LEN); state++; break; case RFB_SERVERINIT+ 4: case RFB_SERVERINIT+ 5: case RFB_SERVERINIT+ 6: case RFB_SERVERINIT+ 7: case RFB_SERVERINIT+ 8: case RFB_SERVERINIT+ 9: case RFB_SERVERINIT+10: case RFB_SERVERINIT+11: case RFB_SERVERINIT+12: case RFB_SERVERINIT+13: case RFB_SERVERINIT+14: case RFB_SERVERINIT+15: case RFB_SERVERINIT+16: case RFB_SERVERINIT+17: case RFB_SERVERINIT+18: case RFB_SERVERINIT+19: state++; break; case RFB_SERVERINIT+23: pstate->sub.vnc.sectype <<= 8; pstate->sub.vnc.sectype |= px[i]; state++; if (pstate->sub.vnc.sectype) { banout_append(banout, PROTO_VNC_INFO, "Name: ", AUTO_LEN); } else { state = RFB_DONE; tcpapi_close(socket); } break; case RFB_SERVERINIT+24: pstate->sub.vnc.sectype--; banout_append_char(banout, PROTO_VNC_INFO, px[i]); if (pstate->sub.vnc.sectype == 0) { banout_append(banout, PROTO_VNC_INFO, "\n", AUTO_LEN); state = RFB_DONE; tcpapi_close(socket); } break; case RFB_DONE: tcpapi_close(socket); i = (unsigned)length; break; default: i = (unsigned)length; break; } pstate->state = state; } /*************************************************************************** ***************************************************************************/ static void * vnc_init(struct Banner1 *banner1) { UNUSEDPARM(banner1); return 0; } /*************************************************************************** ***************************************************************************/ static int vnc_selftest(void) { return 0; } /*************************************************************************** ***************************************************************************/ const struct ProtocolParserStream banner_vnc = { "vnc", 5900, 0, 0, 0, vnc_selftest, vnc_init, vnc_parse, };
12,946
C
.c
340
24.017647
89
0.449767
robertdavidgraham/masscan
23,250
3,042
399
AGPL-3.0
9/7/2024, 9:40:14 AM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
5,373
proto-tcp-rdp.c
robertdavidgraham_masscan/src/proto-tcp-rdp.c
#include "proto-tcp-rdp.h" #include "proto-banner1.h" #include "stack-tcp-api.h" #include "unusedparm.h" #include "masscan-app.h" #include "util-malloc.h" #include "assert.h" #include <ctype.h> #include <string.h> #include "util-safefunc.h" /*************************************************************************** * @param length * Number of bytes remaining in this header, or bytes remaining in * the packet, whichever is fewer. * @return the number of bytes processed ***************************************************************************/ static size_t cc_parse(struct BannerOutput *banout, struct RDPSTUFF *rdp, const unsigned char *px, size_t length) { size_t offset; unsigned state = rdp->cc.state; enum { TYPE, FLAGS, LENGTH, RESERVED, RESULT0, RESULT1, RESULT2, RESULT3, EXTRA, UNKNOWN_PROTOCOL }; for (offset = 0; offset < length; offset++) { unsigned char c = px[offset]; switch (state) { case TYPE: rdp->cc.type = c; state++; break; case FLAGS: rdp->cc.flags = c; state++; break; case LENGTH: rdp->cc.len = c; if (rdp->cc.len < 4) { state = UNKNOWN_PROTOCOL; } else { rdp->cc.len -= 4; state++; } break; case RESERVED: switch (rdp->cc.type) { case 2: /* negotiate success */ case 3: /* negotiate failure */ state = RESULT0; rdp->cc.result = 0; break; default: state = EXTRA; break; } break; case RESULT0: case RESULT1: case RESULT2: case RESULT3: if (rdp->cc.len == 0) state = EXTRA; else { rdp->cc.len--; rdp->cc.result = rdp->cc.result>>8 | (c << 24); state++; if (state == EXTRA) { switch (rdp->cc.type) { case 2: if (rdp->cc.result & 2) banout_append(banout, PROTO_RDP, " NLA-supported", AUTO_LEN); else banout_append(banout, PROTO_RDP, " NLA-unused", AUTO_LEN); break; case 3: if (rdp->cc.result == 5) banout_append(banout, PROTO_RDP, " NLA-unsupported", AUTO_LEN); else banout_append(banout, PROTO_RDP, " failure", AUTO_LEN); break; default: banout_append(banout, PROTO_RDP, " unknown", AUTO_LEN); break; } } } break; case EXTRA: offset = length; break; case UNKNOWN_PROTOCOL: banout_append(banout, PROTO_HEUR, px, length); offset = length; break; } } rdp->cc.state = state; return offset; } /*************************************************************************** * @param length * The number of bytes left in those received, or the number of bytes * left in the COTP contents, whichever is less. * @return the number of bytes processed ***************************************************************************/ static size_t cotp_parse(struct BannerOutput *banout, struct RDPSTUFF *rdp, const unsigned char *px, size_t length) { size_t offset; unsigned state = rdp->cotp.state; enum { LENGTH, PDU_TYPE, DSTREF0, DSTREF1, SRCREF0, SRCREF1, FLAGS, CONTENT, UNKNOWN_PROTOCOL, }; for (offset = 0; offset < length; offset++) { unsigned char c = px[offset]; switch (state) { case LENGTH: rdp->cotp.len = c; if (rdp->cotp.len < 6) { state = UNKNOWN_PROTOCOL; } else { rdp->cotp.len -= 6; state++; } break; case PDU_TYPE: rdp->cotp.type = c; rdp->cotp.srcref = 0; rdp->cotp.dstref = 0; state++; break; case DSTREF0: case DSTREF1: rdp->cotp.dstref = rdp->cotp.dstref<<8 | c; state++; break; case SRCREF0: case SRCREF1: rdp->cotp.dstref = rdp->cotp.dstref<<8 | c; state++; break; case FLAGS: rdp->cotp.flags = c; rdp->cc.state = 0; state++; break; case CONTENT: switch (rdp->cotp.type) { case 0xd0: /* connect confirm */ { size_t length2 = rdp->cotp.len; size_t bytes_parsed; /* In case the TPKT length is more bytes than are in this packet */ if (length2 >= length - offset) length2 = length - offset; bytes_parsed = cc_parse(banout, rdp, px + offset, length2); /* Track how many bytes the sub-parsers parsed, remembering * that when the for-loop increments, it'll increment the offset * by 1. */ assert(bytes_parsed != 0); offset += bytes_parsed - 1; rdp->cotp.len -= (unsigned char)bytes_parsed; /* If we have bytes left in the TPKT, then stay in this state, * otherwise transition to the next TPKT */ if (rdp->cotp.len) state = CONTENT; else state = UNKNOWN_PROTOCOL; } break; default: banout_append(banout, PROTO_RDP, " COTPPDU=unknown", AUTO_LEN); offset = length; break; } break; case UNKNOWN_PROTOCOL: banout_append(banout, PROTO_HEUR, px, length); offset = length; break; } } rdp->cotp.state = state; return offset; } /*************************************************************************** ***************************************************************************/ static void rdp_parse( const struct Banner1 *banner1, void *banner1_private, struct StreamState *pstate, const unsigned char *px, size_t length, struct BannerOutput *banout, struct stack_handle_t *socket) { unsigned state = pstate->state & 0xFFFFFF; struct RDPSTUFF *rdp = &pstate->sub.rdp; size_t offset; enum { TPKT_START, TPKT_RESERVED, TPKT_LENGTH0, TPKT_LENGTH1, TPKT_CONTENT, UNKNOWN_PROTOCOL, }; UNUSEDPARM(banner1_private); UNUSEDPARM(banner1); UNUSEDPARM(socket); for (offset=0; offset<length; offset++) { unsigned char c = px[offset]; switch (state & 0xF) { case TPKT_START: if (c != 3) { /* TPKT version=3 */ state = UNKNOWN_PROTOCOL; offset--; } else { rdp->tpkt_length = 0; rdp->cotp.state = 0; state = TPKT_RESERVED; } break; case TPKT_RESERVED: state++; break; case TPKT_LENGTH0: rdp->tpkt_length = rdp->tpkt_length; state++; break; case TPKT_LENGTH1: rdp->tpkt_length = rdp->tpkt_length<<8 | c; if (rdp->tpkt_length < 4) { state = UNKNOWN_PROTOCOL; } else if (rdp->tpkt_length == 4) { state = 0; } else { rdp->tpkt_length -= 4; state++; } break; case TPKT_CONTENT: { size_t length2 = rdp->tpkt_length; size_t bytes_parsed; /* In case the TPKT length is more bytes than are in this packet */ if (length2 >= length - offset) length2 = length - offset; bytes_parsed = cotp_parse(banout, rdp, px + offset, length2); /* Track how many bytes the sub-parsers parsed, remembering * that when the for-loop increments, it'll increment the offset * by 1. */ assert(bytes_parsed != 0); offset += bytes_parsed - 1; rdp->tpkt_length -= (unsigned short)bytes_parsed; /* If we have bytes left in the TPKT, then stay in this state, * otherwise transition to the next TPKT */ if (rdp->tpkt_length) state = TPKT_CONTENT; else state = TPKT_START; } break; case UNKNOWN_PROTOCOL: banout_append(banout, PROTO_HEUR, px, length); offset = length; break; default: break; } } pstate->state = state; } /*************************************************************************** ***************************************************************************/ static void * rdp_init(struct Banner1 *banner1) { UNUSEDPARM(banner1); return 0; } /*************************************************************************** ***************************************************************************/ static int rdp_selftest_item(const char *input, size_t length, const char *expect) { struct Banner1 *banner1; struct StreamState pstate[1]; struct BannerOutput banout1[1]; struct stack_handle_t more = {0}; int x; /* * Initiate a pseudo-environment for the parser */ banner1 = banner1_create(); banout_init(banout1); memset(&pstate[0], 0, sizeof(pstate[0])); /* * Parse the input payload */ rdp_parse(banner1, 0, pstate, (const unsigned char *)input, length, banout1, &more ); /* * Verify that somewhere in the output is the string * we are looking for */ x = banout_is_contains(banout1, PROTO_RDP, expect); if (x == 0) printf("RDP parser failure: %s\n", expect); banner1_destroy(banner1); banout_release(banout1); return (x?0:1); } /*************************************************************************** ***************************************************************************/ static int rdp_selftest(void) { static const char test1[] = "\x03\x00\x00\x13" "\x0e\xd0\x00\x00\x12\x34\x00\x02\x0f\x08\x00\x02\x00\x00\x00"; static const char test2[] = "\x03\x00\x00\x13" "\x0e\xd0\x00\x00\x12\x34\x00\x03\x00\x08\x00\x05\x00\x00\x00"; int result = 0; result += rdp_selftest_item(test1, sizeof(test1) - 1, "NLA-sup"); result += rdp_selftest_item(test2, sizeof(test2) - 1, "NLA-unsup"); return result; } /*************************************************************************** ***************************************************************************/ static const char rdp_hello[] = "\x03\x00\x00\x2d" "\x28\xe0\x00\x00\x00\x00\x00\x43\x6f\x6f\x6b\x69\x65\x3a\x20\x6d" \ "\x73\x74\x73\x68\x61\x73\x68\x3d" "masscan" "\x0d\x0a\x01\x00" \ "\x08\x00\x03\x00\x00\x00"; /*************************************************************************** ***************************************************************************/ const struct ProtocolParserStream banner_rdp = { "rdp", 3389, rdp_hello, sizeof(rdp_hello)-1, 0, rdp_selftest, rdp_init, rdp_parse, };
13,025
C
.c
348
23.922414
101
0.417572
robertdavidgraham/masscan
23,250
3,042
399
AGPL-3.0
9/7/2024, 9:40:14 AM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
5,377
massip.c
robertdavidgraham_masscan/src/massip.c
#include "massip.h" #include "massip-parse.h" #include "massip-rangesv4.h" #include "massip-rangesv6.h" #include <string.h> #include <ctype.h> void massip_apply_excludes(struct MassIP *targets, struct MassIP *exclude) { rangelist_exclude(&targets->ipv4, &exclude->ipv4); range6list_exclude(&targets->ipv6, &exclude->ipv6); rangelist_exclude(&targets->ports, &exclude->ports); } void massip_optimize(struct MassIP *targets) { rangelist_optimize(&targets->ipv4); range6list_optimize(&targets->ipv6); rangelist_optimize(&targets->ports); targets->count_ports = rangelist_count(&targets->ports); targets->count_ipv4s = rangelist_count(&targets->ipv4); targets->count_ipv6s = range6list_count(&targets->ipv6).lo; targets->ipv4_index_threshold = targets->count_ipv4s * rangelist_count(&targets->ports); } int massip_pick(const struct MassIP *massip, uint64_t index, ipaddress *addr, unsigned *port) { /* * We can return either IPv4 or IPv6 addresses */ if (index < massip->ipv4_index_threshold) { addr->version = 4; addr->ipv4 = rangelist_pick(&massip->ipv4, index % massip->count_ipv4s); *port = rangelist_pick(&massip->ports, index / massip->count_ipv4s); } else { addr->version = 6; index -= massip->ipv4_index_threshold; addr->ipv6 = range6list_pick(&massip->ipv6, index % massip->count_ipv6s); *port = rangelist_pick(&massip->ports, index / massip->count_ipv6s); } return 0; } int massip_has_ip(const struct MassIP *massip, ipaddress ip) { if (ip.version == 6) return range6list_is_contains(&massip->ipv6, ip.ipv6); else return rangelist_is_contains(&massip->ipv4, ip.ipv4); } int massip_has_port(const struct MassIP *massip, unsigned port) { return rangelist_is_contains(&massip->ports, port); } int massip_has_ipv4_targets(const struct MassIP *massip) { return massip->ipv4.count != 0; } int massip_has_target_ports(const struct MassIP *massip) { return massip->ports.count != 0; } int massip_has_ipv6_targets(const struct MassIP *massip) { return massip->ipv6.count != 0; } int massip_add_target_string(struct MassIP *massip, const char *string) { const char *ranges = string; size_t offset = 0; size_t max_offset = strlen(ranges); while (offset < max_offset) { struct Range range; struct Range6 range6; int err; /* Grab the next IPv4 or IPv6 range */ err = massip_parse_range(ranges, &offset, max_offset, &range, &range6); switch (err) { case Ipv4_Address: rangelist_add_range(&massip->ipv4, range.begin, range.end); break; case Ipv6_Address: range6list_add_range(&massip->ipv6, range6.begin, range6.end); break; default: offset = max_offset; /* An error means skipping the rest of the string */ return 1; } while (offset < max_offset && (isspace(ranges[offset]&0xFF) || ranges[offset] == ',')) offset++; } return 0; } int massip_add_port_string(struct MassIP *targets, const char *string, unsigned defaultrange) { unsigned is_error = 0; rangelist_parse_ports(&targets->ports, string, &is_error, defaultrange); if (is_error) return 1; else return 0; } int massip_selftest(void) { struct MassIP targets; struct MassIP excludes; int err; int line; massint128_t count; memset(&targets, 0, sizeof(targets)); memset(&excludes, 0, sizeof(targets)); rangelist_parse_ports(&targets.ports, "80", 0, 0); /* First, create a list of targets */ line = __LINE__; err = massip_add_target_string(&targets, "2607:f8b0:4002:801::2004/124,1111::1"); if (err) goto fail; /* Second, create an exclude list */ line = __LINE__; err = massip_add_target_string(&excludes, "2607:f8b0:4002:801::2004/126,1111::/16"); if (err) goto fail; /* Third, apply the excludes, causing ranges to be removed * from the target list */ massip_apply_excludes(&targets, &excludes); /* Now make sure the count equals the expected count */ line = __LINE__; count = massip_range(&targets); if (count.hi != 0 || count.lo != 12) goto fail; return 0; fail: fprintf(stderr, "[-] massip: test fail, line=%d\n", line); return 1; }
4,426
C
.c
131
28.633588
94
0.654422
robertdavidgraham/masscan
23,250
3,042
399
AGPL-3.0
9/7/2024, 9:40:14 AM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
5,378
proto-coap.c
robertdavidgraham_masscan/src/proto-coap.c
/* CoAP - Constrained Application Protocol https://en.wikipedia.org/wiki/Constrained_Application_Protocol This is a very simple protocol for interacting with IoT devices that have a minimal amount of resources, such as less than a megabyte of RAM. From a scanner point of view, we want to execute the equivalent of: GET /.well-known/core This will return the list of additional items that we can access on the target device. 0 1 2 3 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |Ver| T | TKL | Code | Message ID | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Token (if any, TKL bytes) ... +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Options (if any) ... +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |1 1 1 1 1 1 1 1| Payload (if any) ... +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ */ #include "proto-coap.h" #include "proto-banner1.h" #include "smack.h" #include "unusedparm.h" #include "util-logger.h" #include "masscan-app.h" #include "output.h" #include "stack-tcp-api.h" #include "proto-preprocess.h" #include "proto-ssl.h" #include "proto-udp.h" #include "syn-cookie.h" #include "massip-port.h" #include "util-malloc.h" #include "util-safefunc.h" #include "util-bool.h" #include <ctype.h> #include <string.h> #include <stdlib.h> struct CoapLink { unsigned link_offset; unsigned link_length; unsigned parms_offset; unsigned parms_length; }; /**************************************************************************** ****************************************************************************/ static const char * response_code(unsigned code) { #define CODE(x,y) (((x)<<5) | (y)) switch (code) { case CODE(2,0): return "Okay"; case CODE(2,1): return "Created"; case CODE(2,2): return "Deleted"; case CODE(2,3): return "Valid"; case CODE(2,4): return "Changed"; case CODE(2,5): return "Content"; case CODE(4,0): return "Bad Request"; case CODE(4,1): return "Unauthorized"; case CODE(4,2): return "Bad Option"; case CODE(4,3): return "Forbidden"; case CODE(4,4): return "Not Found"; case CODE(4,5): return "Method Not Allowed"; case CODE(4,6): return "Not Acceptable"; case CODE(4,12): return "Precondition Failed"; case CODE(4,13): return "Request Too Large"; case CODE(4,15): return "Unsupported Content-Format"; case CODE(5,0): return "Internal Server Error"; case CODE(5,1): return "Not Implemented"; case CODE(5,2): return "Bad Gateway"; case CODE(5,3): return "Service Unavailable"; case CODE(5,4): return "Gateway Timeout"; case CODE(5,5): return "Proxying Not Supported"; } switch (code>>5) { case 2: return "Okay"; case 4: return "Error"; default: return "PARSE_ERR"; } } /**************************************************************************** * RFC5987 * attr-char = ALPHA / DIGIT * / "!" / "#" / "$" / "&" / "+" / "-" / "." * / "^" / "_" / "`" / "|" / "~" * ; token except ( "*" / "'" / "%" ) * We need this in parsing the links, which may have parameters afterwards * whose names are in this format. ****************************************************************************/ static bool is_attr_char(unsigned c) { switch (c) { case '!': case '#': case '$': case '&': case '+': case '-': case '.': case '^': case '_': case '`': case '|': case '~': return true; default: return isalnum(c) != 0; } } /**************************************************************************** ****************************************************************************/ static struct CoapLink * parse_links(const unsigned char *px, unsigned offset, unsigned length, size_t *r_count) { struct CoapLink *l; struct CoapLink *links; unsigned count = 0; enum { LINK_BEGIN=0, LINK_VALUE, LINK_END, PARM_BEGIN, PARM_NAME_BEGIN, PARM_VALUE_BEGIN, PARM_QUOTED, PARM_QUOTED_ESCAPE, PARM_NAME, PARM_VALUE, INVALID } state = LINK_BEGIN; /* For selftesting purposes, we pass in nul-terminated strings, * indicated by a length of (~0) */ if (length == ~0) length = (unsigned)strlen((const char *)px); /* Allocate space for at least one result */ links = CALLOC(1, sizeof(*links)); l = &links[0]; l->parms_offset = offset; l->link_offset = offset; for (; offset < length; offset++) switch (state) { case INVALID: offset = length; break; case LINK_BEGIN: /* Ignore leading whitespace */ if (isspace(px[offset])) continue; /* Links must start with "<" character */ if (px[offset] != '<') { state = INVALID; break; } /* Reserve space for next link */ links = REALLOCARRAY(links, ++count+1, sizeof(*links)); links[count].link_offset = length; /* indicate end-of-list by pointing to end-of-input */ links[count].link_length = 0; links[count].parms_offset = length; links[count].parms_length = 0; /* Grab a pointer to this <link> */ l = &links[count-1]; l->link_offset = offset+1; l->parms_offset = l->link_offset; state = LINK_VALUE; break; case LINK_VALUE: if (px[offset] == '>') { /* End of the link, it may be followed by parameters */ state = LINK_END; } else { l->link_length++; } break; case LINK_END: l->parms_offset = offset+1; l->parms_length = 0; if (isspace(px[offset])) { continue; } else if (px[offset] == ',') { /* next link */ state = LINK_BEGIN; } else if (px[offset] == ';') { state = PARM_NAME_BEGIN; } else { state = INVALID; } break; case PARM_BEGIN: if (isspace(px[offset])) { continue; } else if (px[offset] == ',') { /* next link */ l->parms_length = offset - l->parms_offset; state = LINK_BEGIN; } else if (px[offset] == ';') { state = PARM_NAME_BEGIN; } else { state = INVALID; } break; case PARM_NAME_BEGIN: if (isspace(px[offset])) continue; if (!is_attr_char(px[offset])) state = INVALID; else state = PARM_NAME; break; case PARM_NAME: if (isspace(px[offset])) { continue; } else if (px[offset] == '=') { state = PARM_VALUE_BEGIN; } else if (!is_attr_char(px[offset])) { state = INVALID; } break; case PARM_VALUE_BEGIN: if (isspace(px[offset])) continue; else if (px[offset] == '\"') { state = PARM_QUOTED; } else if (offset == ';') { state = PARM_NAME_BEGIN; } else if (px[offset] == ',') { l->parms_length = offset - l->parms_offset; state = LINK_BEGIN; } else state = PARM_VALUE; break; case PARM_VALUE: if (isspace(px[offset])) continue; else if (px[offset] == ';') state = PARM_NAME_BEGIN; else if (px[offset] == ',') { l->parms_length = offset - l->parms_offset; state = LINK_BEGIN; } else { ; /* do nothing */ } break; case PARM_QUOTED: /* RFC2616: quoted-string = ( <"> *(qdtext | quoted-pair ) <"> ) qdtext = <any TEXT except <">> quoted-pair = "\" CHAR */ if (px[offset] == '\\') { state = PARM_QUOTED_ESCAPE; } else if (px[offset] == '\"') { state = PARM_VALUE; } break; case PARM_QUOTED_ESCAPE: state = PARM_QUOTED; break; default: fprintf(stderr, "invalid state\n"); state = INVALID; break; } /* Return an array of links and a count of the number of links */ *r_count = count; return links; } /**************************************************************************** ****************************************************************************/ static bool coap_parse(const unsigned char *px, size_t length, struct BannerOutput *banout, unsigned *request_id) { unsigned version; unsigned type; unsigned code = 0; unsigned token_length = 0; unsigned long long token = 0; unsigned offset; unsigned optnum; unsigned content_format; size_t i; /* All coap responses will be at least 8 bytes */ if (length < 4) { LOG(3, "[-] CoAP: short length\n"); goto not_this_protocol; } /* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |Ver| T | TKL | Code | Message ID | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Token (if any, TKL bytes) ... +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Options (if any) ... +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |1 1 1 1 1 1 1 1| Payload (if any) ... +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ */ version = (px[0]>>6) & 3; type = (px[0]>>4) & 3; token_length = px[0] & 0x0F; code = px[1]; *request_id = px[2]<<8 | px[3]; /* Only version supported is v1 */ if (version != 1) { LOG(3, "[-] CoAP: version=%u\n", version); goto not_this_protocol; } /* Only ACKs suported */ if (type != 2) { LOG(3, "[-] CoAP: type=%u\n", type); goto not_this_protocol; } /* Only token lengths up to 8 bytes are supported. * Token length must fit within the packet */ if (token_length > 8 || 4 + token_length > length) { LOG(3, "[-] CoAP: token-length=%u\n", token_length); goto not_this_protocol; } token = 0; for (i=0; i<token_length; i++) { token = token << 8ULL; token = token | (unsigned long long)px[i]; } /* Response code */ { char buf[64]; snprintf(buf, sizeof(buf), "rsp=%u.%u(%s)", code>>5, code&0x1F, response_code(code)); banout_append(banout, PROTO_COAP, buf, AUTO_LEN); //code >>= 5; } /* If there was a token, the print it. */ if (token) { char buf[64]; snprintf(buf, sizeof(buf), " token=0x%llu", token); banout_append(banout, PROTO_COAP, buf, AUTO_LEN); } /* * Now process the options fields 0 1 2 3 4 5 6 7 +---------------+---------------+ | | | | Option Delta | Option Length | 1 byte | | | +---------------+---------------+ \ \ / Option Delta / 0-2 bytes \ (extended) \ +-------------------------------+ \ \ / Option Length / 0-2 bytes \ (extended) \ +-------------------------------+ \ \ / / \ \ / Option Value / 0 or more bytes \ \ / / \ \ +-------------------------------+ */ offset = 4 + token_length; optnum = 0; content_format = 0; while (offset < length) { unsigned delta; unsigned opt; unsigned optlen; /* Get the 'opt' byte */ opt = px[offset++]; if (opt == 0xFF) break; optlen = (opt>>0) & 0x0F; delta = (opt>>4) & 0x0F; /* Decode the delta field */ switch (delta) { default: optnum += delta; break; case 13: if (offset >= length) { banout_append(banout, PROTO_COAP, " PARSE_ERR", AUTO_LEN); optnum = 0xFFFFFFFF; } else { delta = px[offset++] + 13; optnum += delta; } break; case 14: if (offset + 1 >= length) { banout_append(banout, PROTO_COAP, " PARSE_ERR", AUTO_LEN); optnum = 0xFFFFFFFF; } else { delta = px[offset+0]<<8 | px[offset+1]; delta += 269; offset += 2; optnum += delta; } break; case 15: if (optlen != 15) banout_append(banout, PROTO_COAP, " PARSE_ERR", AUTO_LEN); optnum = 0xFFFFFFFF; } /* Decode the optlen field */ switch (optlen) { default: break; case 13: if (offset >= length) { banout_append(banout, PROTO_COAP, " PARSE_ERR", AUTO_LEN); optnum = 0xFFFFFFFF; } else { optlen = px[offset++] + 13; } break; case 14: if (offset + 1 >= length) { banout_append(banout, PROTO_COAP, " PARSE_ERR", AUTO_LEN); optnum = 0xFFFFFFFF; } else { optlen = px[offset+0]<<8 | px[offset+1]; optlen += 269; offset += 2; } break; } if (offset + optlen > length) { banout_append(banout, PROTO_COAP, " PARSE_ERR", AUTO_LEN); optnum = 0xFFFFFFFF; } /* Process the option contents */ switch (optnum) { case 0xFFFFFFFF: break; case 1: banout_append(banout, PROTO_COAP, " /If-Match/", AUTO_LEN); break; case 3: banout_append(banout, PROTO_COAP, " /Uri-Host/", AUTO_LEN); break; case 4: banout_append(banout, PROTO_COAP, " /Etag", AUTO_LEN); break; case 5: banout_append(banout, PROTO_COAP, " /If-None-Match/", AUTO_LEN); break; case 7: banout_append(banout, PROTO_COAP, " /Uri-Port/", AUTO_LEN); break; case 8: banout_append(banout, PROTO_COAP, " /Location-Path/", AUTO_LEN); break; case 11: banout_append(banout, PROTO_COAP, " /Uri-Path/", AUTO_LEN); break; case 12: banout_append(banout, PROTO_COAP, " /Content-Format/", AUTO_LEN); content_format = 0; for (i=0; i<optlen; i++) { content_format = content_format<<8 | px[offset+i]; } break; case 14: banout_append(banout, PROTO_COAP, " /Max-Age/", AUTO_LEN); break; case 15: banout_append(banout, PROTO_COAP, " /Uri-Query/", AUTO_LEN); break; case 17: banout_append(banout, PROTO_COAP, " /Accept/", AUTO_LEN); break; case 20: banout_append(banout, PROTO_COAP, " /Location-Query/", AUTO_LEN); break; case 35: banout_append(banout, PROTO_COAP, " /Proxy-Uri/", AUTO_LEN); break; case 39: banout_append(banout, PROTO_COAP, " /Proxy-Scheme/", AUTO_LEN); break; case 60: banout_append(banout, PROTO_COAP, " /Size1/", AUTO_LEN); break; default: banout_append(banout, PROTO_COAP, " /(Unknown)/", AUTO_LEN); break; } if (optnum == 0xFFFFFFFF) break; offset += optlen; } switch (content_format) { case 0: banout_append(banout, PROTO_COAP, " text-plain", AUTO_LEN); break; case 40: banout_append(banout, PROTO_COAP, " application/link-format", AUTO_LEN); { struct CoapLink *links; size_t count = 0; links = parse_links(px, offset, (unsigned)length, &count); for (i=0; i<count; i++) { banout_append(banout, PROTO_COAP, " ", AUTO_LEN); banout_append(banout, PROTO_COAP, px+links[i].link_offset, links[i].link_length); } free(links); } break; case 41: banout_append(banout, PROTO_COAP, " application/xml", AUTO_LEN); break; case 42: banout_append(banout, PROTO_COAP, " application/octet-stream", AUTO_LEN); break; case 47: banout_append(banout, PROTO_COAP, " application/exi", AUTO_LEN); break; case 50: banout_append(banout, PROTO_COAP, " application/json", AUTO_LEN); break; default: banout_append(banout, PROTO_COAP, " (unknown-content-type)", AUTO_LEN); break; } LOG(3, "[+] CoAP: valid\n"); return true; not_this_protocol: return false; } /*************************************************************************** ***************************************************************************/ unsigned coap_handle_response(struct Output *out, time_t timestamp, const unsigned char *px, unsigned length, struct PreprocessedInfo *parsed, uint64_t entropy ) { ipaddress ip_them = parsed->src_ip; ipaddress ip_me = parsed->dst_ip; unsigned port_them = parsed->port_src; unsigned port_me = parsed->port_dst; unsigned message_id = 0; unsigned cookie; struct BannerOutput banout[1]; bool is_valid; LOG(1, "[+] COAP\n"); /* Initialize the "banner output" module that we'll use to print * pretty text in place of the raw packet */ banout_init(banout); /* * Do the protocol parsing */ is_valid = coap_parse(px, length, banout, &message_id); /* Validate the "syn-cookie" style information, which should match the "Message ID field*/ cookie = (unsigned)syn_cookie(ip_them, port_them | Templ_UDP, ip_me, port_me, entropy); /*if ((seqno&0xffff) != message_id) goto not_this_protocol;*/ /* See if cookies match. So far, we are allowing responses with the * wrong cookie */ if ((cookie&0xffff) != message_id) banout_append(banout, PROTO_COAP, " IP-MISMATCH", AUTO_LEN); /* Print the banner information, or save to a file, depending */ if (is_valid) { output_report_banner( out, timestamp, ip_them, 17 /*udp*/, parsed->port_src, PROTO_COAP, parsed->ip_ttl, banout_string(banout, PROTO_COAP), banout_string_length(banout, PROTO_COAP)); banout_release(banout); return 0; } else { banout_release(banout); return default_udp_parse(out, timestamp, px, length, parsed, entropy); } } /**************************************************************************** ****************************************************************************/ unsigned coap_udp_set_cookie(unsigned char *px, size_t length, uint64_t seqno) { /* The frame header is 4 bytes long, with bytes 2 and 3 being the Message ID. We can also put up to 8 bytes of a "token" here instead of just using the message ID. +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |Ver| T | TKL | Code | Message ID | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Token (if any, TKL bytes) ... +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ */ if (length < 4) return 0; px[2] = (unsigned char)(seqno >> 8); px[3] = (unsigned char)(seqno >> 0); return 0; } /**************************************************************************** * For the selftest code, tests whether the indicated link is within the * given list. ****************************************************************************/ static int test_is_link(const char *name, const unsigned char *vinput, struct CoapLink *links, size_t count, int line_number) { size_t i; size_t name_length = strlen(name); const char *input = (const char *)vinput; for (i=0; i<count; i++) { const char *name2; if (name_length != links[i].link_length) continue; name2 = input + links[i].link_offset; if (memcmp(name2, name, name_length) != 0) continue; return 1; /* found */ } fprintf(stderr, "[-] proto-coap failed at line number %d\n", line_number); return 0; /* not found */ } /**************************************************************************** ****************************************************************************/ int proto_coap_selftest(void) { struct CoapLink *links; size_t count=0; /* test quoted */ { static const unsigned char *input = (const unsigned char *) "</sensors/temp>;if=\"se\\\"\\;\\,\\<\\>\\\\nsor\",</success>"; links = parse_links(input, 0, (unsigned)(~0), &count); if (!test_is_link("/success", input, links, count, __LINE__)) return 1; } /* test a simple link */ { static const unsigned char *input = (const unsigned char *) "</sensors/temp>;if=\"sensor\""; links = parse_links(input, 0, (unsigned)(~0), &count); if (!test_is_link("/sensors/temp", input, links, count, __LINE__)) return 1; } /* Test a complex dump */ { static const unsigned char *input = (const unsigned char *) "</sensors/temp>;if=\"sensor\"," "</sensors/light>;if=\"sensor\"," "</sensors>;ct=40," "</sensors/temp>;rt=\"temperature-c\";if=\"sensor\"," "</sensors/light>;rt=\"light-lux\";if=\"sensor\"," "</sensors/light>;rt=\"light-lux\";if=\"sensor\"," "</sensors/light>;rt=\"light-lux core.sen-light\";if=\"sensor\"," "</sensors>;ct=40;title=\"Sensor Index\"," "</sensors/temp>;rt=\"temperature-c\";if=\"sensor\"," "</sensors/light>;rt=\"light-lux\";if=\"sensor\"," "<http://www.example.com/sensors/t123>;anchor=\"/sensors/temp\";rel=\"describedby\"," "</t>;anchor=\"/sensors/temp\";rel=\"alternate\"," "</firmware/v2.1>;rt=\"firmware\";sz=262144" ; links = parse_links(input, 0, (unsigned)(~0), &count); if (!test_is_link("/firmware/v2.1", input, links, count, __LINE__)) return 1; } /* Now test an entire packet */ { const char input[] = "\x60\x45\x01\xce\xc1\x28\xff\x3c\x2f\x72\x65\x67\x69\x73\x74\x65" "\x72\x3e\x2c\x3c\x2f\x6e\x64\x6d\x2f\x64\x69\x73\x3e\x2c\x3c\x2f" "\x6e\x64\x6d\x2f\x63\x69\x3e\x2c\x3c\x2f\x6d\x69\x72\x72\x6f\x72" "\x3e\x2c\x3c\x2f\x75\x68\x70\x3e\x2c\x3c\x2f\x6e\x64\x6d\x2f\x6c" "\x6f\x67\x6f\x75\x74\x3e\x2c\x3c\x2f\x6e\x64\x6d\x2f\x6c\x6f\x67" "\x69\x6e\x3e\x2c\x3c\x2f\x69\x6e\x66\x6f\x3e"; unsigned request_id = 0; struct BannerOutput banout[1]; bool is_valid; banout_init(banout); /* parse a test packet */ is_valid = coap_parse( (const unsigned char*)input, sizeof(input)-1, banout, &request_id ); //fprintf(stderr, "[+] %.*s\n", (int)banout_string_length(banout, PROTO_COAP), banout_string(banout, PROTO_COAP)); if (!is_valid) return 1; if (request_id != 462) return 1; { const unsigned char *str = banout_string(banout, PROTO_COAP); size_t str_length = banout_string_length(banout, PROTO_COAP); if (str_length <= 16 && memcmp(str, "rsp=2.5(Content)", 16) != 0) return 1; } banout_release(banout); } return 0; }
25,387
C
.c
655
29.120611
122
0.46095
robertdavidgraham/masscan
23,250
3,042
399
AGPL-3.0
9/7/2024, 9:40:14 AM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
5,382
massip-rangesv6.c
robertdavidgraham_masscan/src/massip-rangesv6.c
/* for tracking IP/port ranges */ #include "massip-rangesv6.h" #include "massip-rangesv4.h" #include "util-malloc.h" #include "util-logger.h" #include "massip.h" #include "massip-parse.h" #include <assert.h> #include <ctype.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <stdint.h> #define BUCKET_COUNT 16 #define REGRESS(i,x) if (!(x)) return (fprintf(stderr, "[-] %u: regression failed %s:%d\n", (unsigned)i, __FILE__, __LINE__)|1) #ifndef false #define false 0 #endif #ifndef true #define true 1 #endif #define EQUAL(x,y) ipv6address_is_equal(x,y) static inline ipv6address _int128_add(ipv6address x, ipv6address y) { ipv6address result; result.lo = x.lo + y.lo; result.hi = x.hi + y.hi + (result.lo < x.lo); return result; } static inline ipv6address _int128_subtract(ipv6address x, ipv6address y) { ipv6address result; result.lo = x.lo - y.lo; result.hi = x.hi - y.hi - (result.lo > x.lo); return result; } static ipv6address _int128_add64(const ipv6address lhs, uint64_t rhs) { ipv6address result = lhs; result.lo += rhs; if (result.lo < lhs.lo) result.hi++; return result; } static inline massint128_t _int128_mult64(massint128_t lhs, uint64_t rhs) { massint128_t result = {0,0}; uint64_t x; uint64_t b; uint64_t a; /* low-order 32 */ a = (rhs>>0) & 0xFFFFFFFFULL; b = (lhs.lo>>0) & 0xFFFFFFFFULL; x = (a * b); result.lo += x; b = (lhs.lo>>32ULL) & 0xFFFFFFFFULL; x = (a * b); result.lo += x<<32ULL; result.hi += x>>32ULL; b = lhs.hi; x = (a * b); result.hi += x; /* next 32 */ a = (rhs>>32ULL) & 0xFFFFFFFFULL; b = (lhs.lo>>0ULL) & 0xFFFFFFFFULL; x = (a * b); result.lo += x<<32ULL; result.hi += (x>>32ULL) + (result.lo < (x<<32ULL)); b = (lhs.lo>>32ULL) & 0xFFFFFFFFULL; x = (a * b); result.hi += x; b = lhs.hi; x = (a * b); result.hi += x<<32ULL; return result; } static int LESS(const ipv6address lhs, const ipv6address rhs) { if (lhs.hi < rhs.hi) return 1; else if (lhs.hi == rhs.hi && lhs.lo < rhs.lo) return 1; else return 0; } #define GREATEREQ(x,y) (!LESS(x,y)) static int LESSEQ(const ipv6address lhs, const ipv6address rhs) { if (lhs.hi < rhs.hi) return 1; if (lhs.hi > rhs.hi) return 0; if (lhs.lo <= rhs.lo) return 1; else return 0; } int range6_is_bad_address(const struct Range6 *range) { return LESS(range->end, range->begin); } static int _int128_is_equals(const ipv6address lhs, const ipv6address rhs) { return lhs.hi == rhs.hi && lhs.lo == rhs.lo; } static ipv6address MINUS_ONE(const ipv6address ip) { ipv6address result; if (ip.lo == 0) { result.hi = ip.hi - 1; result.lo = ~0ULL; } else { result.hi = ip.hi; result.lo = ip.lo - 1; } return result; } static ipv6address PLUS_ONE(const ipv6address ip) { ipv6address result; if (ip.lo == ~0) { result.hi = ip.hi + 1; result.lo = 0; } else { result.hi = ip.hi; result.lo = ip.lo + 1; } return result; } /*************************************************************************** ***************************************************************************/ massint128_t massip_range(struct MassIP *massip) { massint128_t result; result = range6list_count(&massip->ipv6); result = _int128_add64(result, rangelist_count(&massip->ipv4)); result = _int128_mult64(result, rangelist_count(&massip->ports)); return result; } /*************************************************************************** ***************************************************************************/ int range6list_is_contains(const struct Range6List *targets, const ipv6address ip) { unsigned i; for (i=0; i<targets->count; i++) { struct Range6 *range = &targets->list[i]; if (LESSEQ(range->begin, ip) && LESSEQ(ip, range->end)) return 1; } return 0; } /*************************************************************************** * ??? ***************************************************************************/ static void todo_remove_at(struct Range6List *targets, unsigned index) { memmove(&targets->list[index], &targets->list[index+1], (targets->count - index) * sizeof(targets->list[index]) ); targets->count--; } /*************************************************************************** * Test if two ranges overlap. * This is easiest done by testing that they don't overlap, and inverting * the result. * Note that adjacent addresses overlap. ***************************************************************************/ static int range6_is_overlap(const struct Range6 lhs, const struct Range6 rhs) { static const ipv6address FFFF = {~0ULL, ~0ULL}; if (LESS(lhs.begin, rhs.begin)) { if (EQUAL(lhs.end, FFFF) || GREATEREQ(PLUS_ONE(lhs.end), rhs.begin)) return 1; } if (GREATEREQ(lhs.begin, rhs.begin)) { if (LESSEQ(lhs.end, rhs.end)) return 1; } if (LESS(rhs.begin, lhs.begin)) { if (EQUAL(rhs.end, FFFF) || GREATEREQ(PLUS_ONE(rhs.end), lhs.begin)) return 1; } if (GREATEREQ(rhs.begin, lhs.begin)) { if (LESSEQ(rhs.end, lhs.end)) return 1; } return 0; #if 0 static const ipv6address zero = {0, 0}; ipv6address lhs_endm = MINUS_ONE(lhs.end); ipv6address rhs_endm = MINUS_ONE(rhs.end); /* llll rrrr */ if (LESS(zero, lhs.end) && LESS(lhs_endm, rhs.begin)) return 0; /* rrrr llll */ if (LESS(zero, rhs.end) && LESS(rhs_endm, lhs.begin)) return 0; return 1; #endif } /*************************************************************************** * Combine two ranges, such as when they overlap. ***************************************************************************/ static void range6_combine(struct Range6 *lhs, const struct Range6 rhs) { if (LESSEQ(rhs.begin, lhs->begin)) lhs->begin = rhs.begin; if (LESSEQ(lhs->end, rhs.end)) lhs->end = rhs.end; } /*************************************************************************** * Callback for qsort() for comparing two ranges ***************************************************************************/ static int range6_compare(const void *lhs, const void *rhs) { struct Range6 *left = (struct Range6 *)lhs; struct Range6 *right = (struct Range6 *)rhs; if (ipv6address_is_equal(left->begin, right->begin)) return 0; else if (LESS(left->begin, right->begin)) return -1; else return 1; } /*************************************************************************** ***************************************************************************/ void range6list_sort(struct Range6List *targets) { size_t i; struct Range6List newlist = {0}; size_t original_count = targets->count; /* Empty lists are, of course, sorted. We need to set this * to avoid an error later on in the code which asserts that * the lists are sorted */ if (targets->count == 0) { targets->is_sorted = 1; return; } /* If it's already sorted, then skip this */ if (targets->is_sorted) { return; } /* First, sort the list */ LOG(3, "[+] range6:sort: sorting...\n"); qsort( targets->list, /* the array to sort */ targets->count, /* number of elements to sort */ sizeof(targets->list[0]), /* size of element */ range6_compare); /* Second, combine all overlapping ranges. We do this by simply creating * a new list from a sorted list, so we don't have to remove things in the * middle when collapsing overlapping entries together, which is painfully * slow. */ LOG(3, "[+] range:sort: combining...\n"); for (i=0; i<targets->count; i++) { range6list_add_range(&newlist, targets->list[i].begin, targets->list[i].end); } LOG(3, "[+] range:sort: combined from %u elements to %u elements\n", original_count, newlist.count); free(targets->list); targets->list = newlist.list; targets->count = newlist.count; newlist.list = 0; LOG(2, "[+] range:sort: done...\n"); targets->is_sorted = 1; } void range6list_add_range(struct Range6List *targets, ipv6address begin, ipv6address end) { struct Range6 range; range.begin = begin; range.end = end; /* auto-expand the list if necessary */ if (targets->count + 1 >= targets->max) { targets->max = targets->max * 2 + 1; targets->list = REALLOCARRAY(targets->list, targets->max, sizeof(targets->list[0])); } /* If empty list, then add this one */ if (targets->count == 0) { targets->list[0] = range; targets->count++; targets->is_sorted = 1; return; } /* If new range overlaps the last range in the list, then combine it * rather than appending it. This is an optimization for the fact that * we often read in sequential addresses */ if (range6_is_overlap(targets->list[targets->count - 1], range)) { range6_combine(&targets->list[targets->count - 1], range); targets->is_sorted = 0; return; } /* append to the end of our list */ targets->list[targets->count] = range; targets->count++; targets->is_sorted = 0; } /*************************************************************************** ***************************************************************************/ void range6list_remove_all(struct Range6List *targets) { if (targets->list) free(targets->list); if (targets->picker) free(targets->picker); memset(targets, 0, sizeof(*targets)); } /*************************************************************************** ***************************************************************************/ void range6list_merge(struct Range6List *list1, const struct Range6List *list2) { unsigned i; for (i=0; i<list2->count; i++) { range6list_add_range(list1, list2->list[i].begin, list2->list[i].end); } } /*************************************************************************** ***************************************************************************/ void range6list_remove_range(struct Range6List *targets, const ipv6address begin, const ipv6address end) { unsigned i; struct Range6 x; x.begin = begin; x.end = end; /* See if the range overlaps any exist range already in the * list */ for (i = 0; i < targets->count; i++) { if (!range6_is_overlap(targets->list[i], x)) continue; /* If the removal-range wholly covers the range, delete * it completely */ if (LESSEQ(begin, targets->list[i].begin) && LESSEQ(targets->list[i].end, end)) { todo_remove_at(targets, i); i--; continue; } /* If the removal-range bisects the target-rage, truncate * the lower end and add a new high-end */ if (LESSEQ(targets->list[i].begin, begin) && LESSEQ(end, targets->list[i].end)) { struct Range6 newrange; newrange.begin = PLUS_ONE(end); newrange.end = targets->list[i].end; targets->list[i].end = MINUS_ONE(begin); range6list_add_range(targets, newrange.begin, newrange.end); i--; continue; } /* If overlap on the lower side */ if (LESSEQ(targets->list[i].begin, end) && LESSEQ(end, targets->list[i].end)) { targets->list[i].begin = PLUS_ONE(end); } /* If overlap on the upper side */ if (LESSEQ(targets->list[i].begin, begin) && LESSEQ(begin, targets->list[i].end)) { targets->list[i].end = MINUS_ONE(begin); } } } void range6list_remove_range2(struct Range6List *targets, struct Range6 range) { range6list_remove_range(targets, range.begin, range.end); } /*************************************************************************** ***************************************************************************/ ipv6address range6list_exclude( struct Range6List *targets, const struct Range6List *excludes) { ipv6address count = {0,0}; unsigned i; for (i=0; i<excludes->count; i++) { struct Range6 range = excludes->list[i]; ipv6address x; x = _int128_subtract(range.end, range.begin); x = _int128_add64(x, 1); count = _int128_add(count, x); range6list_remove_range(targets, range.begin, range.end); } return count; } /*************************************************************************** ***************************************************************************/ massint128_t range6list_count(const struct Range6List *targets) { unsigned i; ipv6address result = {0,0}; for (i=0; i<targets->count; i++) { ipv6address x; x = _int128_subtract(targets->list[i].end, targets->list[i].begin); if (x.hi == ~0ULL && x.lo == ~0ULL) return x; /* overflow */ x = _int128_add64(x, 1); result = _int128_add(result, x); } return result; } /*************************************************************************** ***************************************************************************/ ipv6address range6list_pick(const struct Range6List *targets, uint64_t index) { size_t maxmax = targets->count; size_t min = 0; size_t max = targets->count; size_t mid; const size_t *picker = targets->picker; if (picker == NULL) { fprintf(stderr, "[-] ipv6 picker is null\n"); exit(1); } for (;;) { mid = min + (max-min)/2; if (index < picker[mid]) { max = mid; continue; } if (index >= picker[mid]) { if (mid + 1 == maxmax) break; else if (index < picker[mid+1]) break; else min = mid+1; } } return _int128_add64(targets->list[mid].begin, (index - picker[mid])); } /*************************************************************************** * The normal "pick" function is a linear search, which is slow when there * are a lot of ranges. Therefore, the "pick2" creates sort of binary * search that'll be a lot faster. We choose "binary search" because * it's the most cache-efficient, having the least overhead to fit within * the cache. ***************************************************************************/ void range6list_optimize(struct Range6List *targets) { size_t *picker; size_t i; ipv6address total = {0,0}; if (targets->count == 0) return; /* This technique only works when the targets are in * ascending order */ if (!targets->is_sorted) range6list_sort(targets); if (targets->picker) free(targets->picker); picker = REALLOCARRAY(NULL, targets->count, sizeof(*picker)); for (i=0; i<targets->count; i++) { ipv6address x; picker[i] = (size_t)total.lo; x = _int128_subtract(targets->list[i].end, targets->list[i].begin); x = _int128_add64(x, 1); total = _int128_add(total, x); } targets->picker = picker; } /*************************************************************************** * Provide my own rand() simply to avoid static-analysis warning me that * 'rand()' is unrandom, when in fact we want the non-random properties of * rand() for regression testing. ***************************************************************************/ static unsigned r_rand(unsigned *seed) { static const unsigned a = 214013; static const unsigned c = 2531011; *seed = (*seed) * a + c; return (*seed)>>16 & 0x7fff; } /*************************************************************************** ***************************************************************************/ static int regress_pick2() { unsigned i; unsigned seed = 0; /* */ for (i=0; i<65536; i++) { ipv6address a; ipv6address b; ipv6address c; ipv6address d; a.hi = r_rand(&seed); a.lo = (unsigned long long)r_rand(&seed)<<49ULL; b.hi = r_rand(&seed); b.lo = 0x8765432100000000ULL; c = _int128_add(a, b); d = _int128_subtract(c, b); if (!_int128_is_equals(a, d)) { fprintf(stderr, "[-] %s:%d: test failed (%u)\n", __FILE__, __LINE__, (unsigned)i); return 1; } } /* * Run 100 randomized regression tests */ for (i=3; i<100; i++) { unsigned j; unsigned num_targets; ipv6address begin = {0}; ipv6address end = {0}; struct Range6List targets[1]; struct Range6List duplicate[1]; uint64_t range; ipv6address x; seed = i; /* Create a new target list */ memset(targets, 0, sizeof(targets[0])); /* fill the target list with random ranges */ num_targets = r_rand(&seed)%5 + 1; for (j=0; j<num_targets; j++) { begin.lo += r_rand(&seed)%10; end.lo = begin.lo + r_rand(&seed)%10; range6list_add_range(targets, begin, end); } /* Optimize for faster 'picking' addresses from an index */ range6list_optimize(targets); /* Duplicate the targetlist using the picker */ memset(duplicate, 0, sizeof(duplicate[0])); x = range6list_count(targets); if (x.hi) { fprintf(stderr, "[-] range6: range too big\n"); return 1; } range = x.lo; for (j=0; j<range; j++) { ipv6address addr; addr = range6list_pick(targets, j); range6list_add_range(duplicate, addr, addr); } /* at this point, the two range lists should be identical */ REGRESS(i, targets->count == duplicate->count); REGRESS(i, memcmp(targets->list, duplicate->list, targets->count*sizeof(targets->list[0])) == 0); range6list_remove_all(targets); range6list_remove_all(duplicate); } return 0; } /*************************************************************************** * Called during "make regress" to run a regression test over this module. ***************************************************************************/ int ranges6_selftest(void) { struct Range6 r; struct Range6List targets[1]; int err; REGRESS(0, regress_pick2() == 0); memset(targets, 0, sizeof(targets[0])); #define ERROR() fprintf(stderr, "selftest: failed %s:%u\n", __FILE__, __LINE__); err = massip_parse_range("2001:0db8:85a3:0000:0000:8a2e:0370:7334", 0, 0, 0, &r); if (err != Ipv6_Address) ERROR(); /* test for the /0 CIDR block, since we'll be using that a lot to scan the entire * Internet */ if (r.begin.hi != 0x20010db885a30000ULL) return 1; if (r.begin.lo != 0x00008a2e03707334ULL) return 1; return 0; }
19,435
C
.c
584
27.638699
127
0.520067
robertdavidgraham/masscan
23,250
3,042
399
AGPL-3.0
9/7/2024, 9:40:14 AM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
5,385
proto-tcp-telnet.h
robertdavidgraham_masscan/src/proto-tcp-telnet.h
#ifndef PROTO_TELNET_H #define PROTO_TELNET_H #include "proto-banner1.h" extern const struct ProtocolParserStream banner_telnet; #endif
138
C
.c
5
26.2
55
0.839695
robertdavidgraham/masscan
23,250
3,042
399
AGPL-3.0
9/7/2024, 9:40:14 AM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
5,390
in-binary.c
robertdavidgraham_masscan/src/in-binary.c
/* Read in the binary file produced by "out-binary.c". This allows you to translate the "binary" format into any of the other output formats. */ #include "massip-addr.h" #include "in-binary.h" #include "masscan.h" #include "masscan-app.h" #include "masscan-status.h" #include "main-globals.h" #include "output.h" #include "util-safefunc.h" #include "in-filter.h" #include "in-report.h" #include "util-malloc.h" #include "util-logger.h" #include <stdlib.h> #include <assert.h> #ifdef _MSC_VER #pragma warning(disable:4996) #endif static const size_t BUF_MAX = 1024*1024; struct MasscanRecord { unsigned timestamp; ipaddress ip; unsigned char ip_proto; unsigned short port; unsigned char reason; unsigned char ttl; unsigned char mac[6]; enum ApplicationProtocol app_proto; }; /*************************************************************************** ***************************************************************************/ static void parse_status(struct Output *out, enum PortStatus status, /* open/closed */ const unsigned char *buf, size_t buf_length) { struct MasscanRecord record; if (buf_length < 12) return; /* parse record */ record.timestamp = buf[0]<<24 | buf[1]<<16 | buf[2]<<8 | buf[3]; record.ip.ipv4 = buf[4]<<24 | buf[5]<<16 | buf[6]<<8 | buf[7]; record.ip.version = 4; record.port = buf[8]<<8 | buf[9]; record.reason = buf[10]; record.ttl = buf[11]; /* if ARP, then there will be a MAC address */ if (record.ip.ipv4 == 0 && buf_length >= 12+6) memcpy(record.mac, buf+12, 6); else memset(record.mac, 0, 6); if (out->when_scan_started == 0) out->when_scan_started = record.timestamp; switch (record.port) { case 53: case 123: case 137: case 161: record.ip_proto = 17; break; case 36422: case 36412: case 2905: record.ip_proto = 132; break; default: record.ip_proto = 6; break; } /* * Now report the result */ output_report_status(out, record.timestamp, status, record.ip, record.ip_proto, record.port, record.reason, record.ttl, record.mac); } /*************************************************************************** ***************************************************************************/ static void parse_status2(struct Output *out, enum PortStatus status, /* open/closed */ const unsigned char *buf, size_t buf_length, struct MassIP *filter) { struct MasscanRecord record; if (buf_length < 13) return; /* parse record */ record.timestamp = buf[0]<<24 | buf[1]<<16 | buf[2]<<8 | buf[3]; record.ip.ipv4 = buf[4]<<24 | buf[5]<<16 | buf[6]<<8 | buf[7]; record.ip.version = 4; record.ip_proto = buf[8]; record.port = buf[9]<<8 | buf[10]; record.reason = buf[11]; record.ttl = buf[12]; /* if ARP, then there will be a MAC address */ if (record.ip.ipv4 == 0 && buf_length >= 13+6) memcpy(record.mac, buf+13, 6); else memset(record.mac, 0, 6); if (out->when_scan_started == 0) out->when_scan_started = record.timestamp; /* Filter for known IP/ports, if specified on command-line */ if (filter && filter->count_ipv4s) { if (!massip_has_ip(filter, record.ip)) return; } if (filter && filter->count_ports) { if (!massip_has_port(filter, record.port)) return; } /* * Now report the result */ output_report_status(out, record.timestamp, status, record.ip, record.ip_proto, record.port, record.reason, record.ttl, record.mac); } static unsigned char _get_byte(const unsigned char *buf, size_t length, size_t *offset) { unsigned char result; if (*offset < length) { result = buf[*offset]; } else { result = 0xFF; } (*offset)++; return result; } static unsigned _get_integer(const unsigned char *buf, size_t length, size_t *r_offset) { unsigned result; size_t offset = *r_offset; (*r_offset) += 4; if (offset + 4 <= length) { result = buf[offset+0]<<24 | buf[offset+1]<<16 | buf[offset+2]<<8 | buf[offset+3]<<0; } else { result = 0xFFFFFFFF; } return result; } static unsigned short _get_short(const unsigned char *buf, size_t length, size_t *r_offset) { unsigned short result; size_t offset = *r_offset; (*r_offset) += 2; if (offset + 2 <= length) { result = buf[offset+0]<<8 | buf[offset+1]<<0; } else { result = 0xFFFF; } return result; } static unsigned long long _get_long(const unsigned char *buf, size_t length, size_t *r_offset) { unsigned long long result; size_t offset = *r_offset; (*r_offset) += 8; if (offset + 8 <= length) { result = (unsigned long long)buf[offset+0]<<56ULL | (unsigned long long)buf[offset+1]<<48ULL | (unsigned long long)buf[offset+2]<<40ULL | (unsigned long long)buf[offset+3]<<32ULL | (unsigned long long)buf[offset+4]<<24ULL | (unsigned long long)buf[offset+5]<<16ULL | (unsigned long long)buf[offset+6]<<8ULL | (unsigned long long)buf[offset+7]<<0ULL; } else { result = 0xFFFFFFFFffffffffULL; } return result; } /*************************************************************************** ***************************************************************************/ static void parse_status6(struct Output *out, enum PortStatus status, /* open/closed */ const unsigned char *buf, size_t length, struct MassIP *filter) { struct MasscanRecord record; size_t offset = 0; /* parse record */ record.timestamp = _get_integer(buf, length, &offset); record.ip_proto = _get_byte(buf, length, &offset); record.port = _get_short(buf, length, &offset); record.reason = _get_byte(buf, length, &offset); record.ttl = _get_byte(buf, length, &offset); record.ip.version= _get_byte(buf, length, &offset); if (record.ip.version != 6) { fprintf(stderr, "[-] corrupt record\n"); return; } record.ip.ipv6.hi = _get_long(buf, length, &offset); record.ip.ipv6.lo = _get_long(buf, length, &offset); if (out->when_scan_started == 0) out->when_scan_started = record.timestamp; /* Filter for known IP/ports, if specified on command-line */ if (filter && filter->count_ipv4s) { if (!massip_has_ip(filter, record.ip)) return; } if (filter && filter->count_ports) { if (!massip_has_port(filter, record.port)) return; } /* * Now report the result */ output_report_status(out, record.timestamp, status, record.ip, record.ip_proto, record.port, record.reason, record.ttl, record.mac); } /*************************************************************************** ***************************************************************************/ static void parse_banner6(struct Output *out, unsigned char *buf, size_t length, const struct MassIP *filter, const struct RangeList *btypes) { struct MasscanRecord record; size_t offset = 0; /* * Parse the parts that are common to most records */ record.timestamp = _get_integer(buf, length, &offset); record.ip_proto = _get_byte(buf, length, &offset); record.port = _get_short(buf, length, &offset); record.app_proto = _get_short(buf, length, &offset); record.ttl = _get_byte(buf, length, &offset); record.ip.version= _get_byte(buf, length, &offset); if (record.ip.version != 6) { fprintf(stderr, "[-] corrupt record\n"); return; } record.ip.ipv6.hi = _get_long(buf, length, &offset); record.ip.ipv6.lo = _get_long(buf, length, &offset); if (out->when_scan_started == 0) out->when_scan_started = record.timestamp; /* * Filter out records if requested */ if (!readscan_filter_pass(record.ip, record.port, record.app_proto, filter, btypes)) return; /* * Now print the output */ if (offset > length) return; output_report_banner( out, record.timestamp, record.ip, record.ip_proto, /* TCP=6, UDP=17 */ record.port, record.app_proto, /* HTTP, SSL, SNMP, etc. */ record.ttl, /* ttl */ buf+offset, (unsigned)(length-offset) ); } /*************************************************************************** * [OBSOLETE] * This parses an old version of the banner record. I've still got files * hanging around with this version, so I'm keeping it in the code for * now, but eventually I'll get rid of it. ***************************************************************************/ static void parse_banner3(struct Output *out, unsigned char *buf, size_t buf_length) { struct MasscanRecord record; /* * Parse the parts that are common to most records */ record.timestamp = buf[0]<<24 | buf[1]<<16 | buf[2]<<8 | buf[3]; record.ip.ipv4 = buf[4]<<24 | buf[5]<<16 | buf[6]<<8 | buf[7]; record.ip.version = 4; record.port = buf[8]<<8 | buf[9]; record.app_proto = buf[10]<<8 | buf[11]; if (out->when_scan_started == 0) out->when_scan_started = record.timestamp; /* * Now print the output */ output_report_banner( out, record.timestamp, record.ip, 6, /* this is always TCP */ record.port, record.app_proto, 0, /* ttl */ buf+12, (unsigned)buf_length-12 ); } /*************************************************************************** * Parse the BANNER record, extracting the timestamp, IP address, and port * number. We also convert the banner string into a safer form. ***************************************************************************/ static void parse_banner4(struct Output *out, unsigned char *buf, size_t buf_length) { struct MasscanRecord record; if (buf_length < 13) return; /* * Parse the parts that are common to most records */ record.timestamp = buf[0]<<24 | buf[1]<<16 | buf[2]<<8 | buf[3]; record.ip.ipv4 = buf[4]<<24 | buf[5]<<16 | buf[6]<<8 | buf[7]; record.ip.version = 4; record.ip_proto = buf[8]; record.port = buf[9]<<8 | buf[10]; record.app_proto = buf[11]<<8 | buf[12]; if (out->when_scan_started == 0) out->when_scan_started = record.timestamp; /* * Now print the output */ output_report_banner( out, record.timestamp, record.ip, record.ip_proto, /* TCP=6, UDP=17 */ record.port, record.app_proto, /* HTTP, SSL, SNMP, etc. */ 0, /* ttl */ buf+13, (unsigned)buf_length-13 ); } /*************************************************************************** ***************************************************************************/ static void parse_banner9(struct Output *out, unsigned char *buf, size_t buf_length, const struct MassIP *filter, const struct RangeList *btypes) { struct MasscanRecord record; unsigned char *data = buf+14; size_t data_length = buf_length-14; if (buf_length < 14) return; /* * Parse the parts that are common to most records */ record.timestamp = buf[0]<<24 | buf[1]<<16 | buf[2]<<8 | buf[3]; record.ip.ipv4 = buf[4]<<24 | buf[5]<<16 | buf[6]<<8 | buf[7]; record.ip.version = 4; record.ip_proto = buf[8]; record.port = buf[9]<<8 | buf[10]; record.app_proto = buf[11]<<8 | buf[12]; record.ttl = buf[13]; if (out->when_scan_started == 0) out->when_scan_started = record.timestamp; /* * KLUDGE: when doing SSL stuff, add a IP:name pair to a database * so we can annotate [VULN] strings with this information */ //readscan_report(record.ip, record.app_proto, &data, &data_length); /* * Filter out records if requested */ if (!readscan_filter_pass(record.ip, record.port, record.app_proto, filter, btypes)) return; /* * Now print the output */ output_report_banner( out, record.timestamp, record.ip, record.ip_proto, /* TCP=6, UDP=17 */ record.port, record.app_proto, /* HTTP, SSL, SNMP, etc. */ record.ttl, /* ttl */ data, (unsigned)data_length ); } /*************************************************************************** * Read in the file, one record at a time. ***************************************************************************/ static uint64_t _binaryfile_parse(struct Output *out, const char *filename, struct MassIP *filter, const struct RangeList *btypes) { FILE *fp = 0; unsigned char *buf = 0; size_t bytes_read; uint64_t total_records = 0; /* Allocate a buffer of up to one megabyte per record */ buf = MALLOC(BUF_MAX); /* Open the file */ fp = fopen(filename, "rb"); if (fp == NULL) { fprintf(stderr, "[-] FAIL: --readscan\n"); fprintf(stderr, "[-] %s: %s\n", filename, strerror(errno)); goto end; } LOG(0, "[+] --readscan %s\n", filename); if (feof(fp)) { LOG(0, "[-] %s: file is empty\n", filename); goto end; } /* first record is pseudo-record */ bytes_read = fread(buf, 1, 'a'+2, fp); if (bytes_read < 'a'+2) { LOG(0, "[-] %s: %s\n", filename, strerror(errno)); goto end; } /* Make sure it's got the format string */ if (memcmp(buf, "masscan/1.1", 11) != 0) { LOG(0, "[-] %s: unknown file format (expeced \"masscan/1.1\")\n", filename); goto end; } /* * Look for start time */ if (buf[11] == '.' && strtoul((char*)buf+12,0,0) >= 2) { unsigned i; /* move to next field */ for (i=0; i<'a' && buf[i] && buf[i] != '\n'; i++) ; i++; if (buf[i] == 's') i++; if (buf[i] == ':') i++; /* extract timestamp */ if (i < 'a') out->when_scan_started = strtoul((char*)buf+i,0,0); } /* Now read all records */ for (;;) { unsigned type; unsigned length; /* [TYPE] * This is one or more bytes indicating the type of type of the * record */ bytes_read = fread(buf, 1, 1, fp); if (bytes_read != 1) break; type = buf[0] & 0x7F; while (buf[0] & 0x80) { bytes_read = fread(buf, 1, 1, fp); if (bytes_read != 1) break; type = (type << 7) | (buf[0] & 0x7F); } /* [LENGTH] * Is one byte for lengths smaller than 127 bytes, or two * bytes for lengths up to 16384. */ bytes_read = fread(buf, 1, 1, fp); if (bytes_read != 1) break; length = buf[0] & 0x7F; while (buf[0] & 0x80) { bytes_read = fread(buf, 1, 1, fp); if (bytes_read != 1) break; length = (length << 7) | (buf[0] & 0x7F); } if (length > BUF_MAX) { LOG(0, "[-] file corrupt\n"); goto end; } /* get the remainder of the record */ bytes_read = fread(buf, 1, length, fp); if (bytes_read < length) break; /* eof */ /* Depending on record type, do something different */ switch (type) { case 1: /* STATUS: open */ if (!btypes->count) parse_status(out, PortStatus_Open, buf, bytes_read); break; case 2: /* STATUS: closed */ if (!btypes->count) parse_status(out, PortStatus_Closed, buf, bytes_read); break; case 3: /* BANNER */ parse_banner3(out, buf, bytes_read); break; case 4: if (fread(buf+bytes_read,1,1,fp) != 1) { LOG(0, "[-] read() error\n"); exit(1); } bytes_read++; parse_banner4(out, buf, bytes_read); break; case 5: parse_banner4(out, buf, bytes_read); break; case 6: /* STATUS: open */ if (!btypes->count) parse_status2(out, PortStatus_Open, buf, bytes_read, filter); break; case 7: /* STATUS: closed */ if (!btypes->count) parse_status2(out, PortStatus_Closed, buf, bytes_read, filter); break; case 9: parse_banner9(out, buf, bytes_read, filter, btypes); break; case 10: /* Open6 */ if (!btypes->count) parse_status6(out, PortStatus_Open, buf, bytes_read, filter); break; case 11: /* Closed6 */ if (!btypes->count) parse_status6(out, PortStatus_Closed, buf, bytes_read, filter); break; case 13: /* Banner6 */ parse_banner6(out, buf, bytes_read, filter, btypes); break; case 'm': /* FILEHEADER */ //goto end; break; default: LOG(0, "[-] file corrupt: unknown type %u\n", type); goto end; } total_records++; if ((total_records & 0xFFFF) == 0) LOG(0, "[+] %s: %8" PRIu64 "\r", filename, total_records); } end: if (buf) free(buf); if (fp) fclose(fp); return total_records; } /***************************************************************************** * When masscan is called with the "--readscan" parameter, it doesn't * do a scan of the live network, but instead reads scan results from * a file. Those scan results can then be written out in any of the * other formats. This preserves the original timestamps. *****************************************************************************/ void readscan_binary_scanfile(struct Masscan *masscan, int arg_first, int arg_max, char *argv[]) { struct Output *out; int i; /* * Create the output system, such as XML or JSON output */ out = output_create(masscan, 0); /* * Set the start time to zero. We'll read it from the first file * that we parse */ out->when_scan_started = 0; /* * We don't parse the entire argument list, just a subrange * containing the list of files. The 'arg_first' parameter * points to the first filename after the '--readscan' * parameter, and 'arg_max' is the parameter after * the last filename. For example, consider an argument list that * looks like: * masscan --foo --readscan file1.scan file2.scan --bar * Then arg_first=3 and arg_max=5. */ for (i=arg_first; i<arg_max; i++) { _binaryfile_parse(out, argv[i], &masscan->targets, &masscan->banner_types); } /* Done! */ output_destroy(out); }
20,421
C
.c
606
25.486799
83
0.500305
robertdavidgraham/masscan
23,250
3,042
399
AGPL-3.0
9/7/2024, 9:40:14 AM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
5,392
massip-rangesv4.c
robertdavidgraham_masscan/src/massip-rangesv4.c
/* IPv4 and port ranges This is one of the more integral concepts to how masscan works internally. We combine all the input addresses and address ranges into a sorted list of 'target' IP addresses. This allows us to enumerate all the addresses in order by incrementing a simple index. It is that index that we randomize in order to produce random output, but internally, everything is sorted. Sorting the list allows us to remove duplicates. It also allows us to apply the 'excludes' directly to the input list. In other words, other scanners typically work by selecting an IP address at random, then checking to see if it's been excluded, then skipping it. In this scanner, however, we remove all the excluded address from the targets list before we start scanning. This module has been tuned to support mass lists of millions of target IPv4 addresses and excludes. This has required: - a fast way to parse the address from a file (see range-file.c) - fast sort (just using qsort() from the standard C library) - fast application of exludes, using an optimal O(n + m) linear algorithm, where 'n' is the number of targets, and 'm' is the number of excluded ranges. Large lists can still take a bit to process. On a fast server with 7-million input ranges/addresses and 5000 exclude ranges/addresses, it takes almost 3 seconds to process everything before starting. */ #include "massip-rangesv4.h" #include "massip-port.h" #include "util-logger.h" #include "util-bool.h" #include "util-malloc.h" #include <assert.h> #include <ctype.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <stdint.h> #ifdef _MSC_VER #pragma warning(disable:4204) #endif #define BUCKET_COUNT 16 #define REGRESS(x) if (!(x)) return (fprintf(stderr, "regression failed %s:%d\n", __FILE__, __LINE__)|1) /* An invalid range, where begin comes after the end */ static struct Range INVALID_RANGE = {2,1}; /*************************************************************************** * Does a linear search to see if the list contains the address/port. * FIXME: This should be upgraded to a binary search. However, we don't * really use it in any performance critical code, so it's okay * as a linear search. ***************************************************************************/ int rangelist_is_contains(const struct RangeList *targets, unsigned addr) { unsigned i; for (i=0; i<targets->count; i++) { struct Range *range = &targets->list[i]; if (range->begin <= addr && addr <= range->end) return 1; } return 0; } /*************************************************************************** * Returns the first CIDR range (which can be specified with prefix bits) * that fits within the input range. For example, consider the range * [10.0.0.4->10.0.0.255]. This does't match the bigger CIDR range. * The first range that would fit would be [10.0.0.04/30], or * [10.0.0.4->10.0.0.7]. * * Using this function allows us to decompose ***************************************************************************/ struct Range range_first_cidr(const struct Range range, unsigned *prefix_bits) { struct Range result = {range.begin, range.end}; unsigned zbits = 0; /* Kludge: Special Case: * All inputs work but the boundary case of [0.0.0.0/0] or * [0.0.0.0-255.255.255.255]. I can't be bothered to figure out * why the algorithm doesn't work with this range, so I'm just * going to special case it here*/ if (range.begin == 0 && range.end == 0xFFFFffff) { if (prefix_bits != NULL) *prefix_bits = 0; return range; } /* Count the number of trailing/suffix zeros, which may be range * from none (0) to 32 (all bits are 0) */ for (zbits = 0; zbits <= 32; zbits++) { if ((range.begin & (1<<zbits)) != 0) break; } /* Now search for the largest CIDR range that starts with this * begining address that fits within the ending address*/ while (zbits > 0) { unsigned mask = ~(0xFFFFFFFF << zbits); if (range.begin + mask > range.end) zbits--; else break; } result.begin = range.begin; result.end = range.begin + ~(0xFFFFffff << zbits); if (prefix_bits != NULL) *prefix_bits = 32-zbits; return result; } bool range_is_cidr(const struct Range range, unsigned *prefix_bits) { struct Range out = range_first_cidr(range, prefix_bits); if (out.begin == range.begin && out.end == range.end) return true; else { if (prefix_bits != NULL) *prefix_bits = 0xFFFFFFFF; return false; } } /*************************************************************************** * Selftest for the above function. ***************************************************************************/ static int selftest_range_first_cidr(void) { static struct { struct Range in; struct Range out; unsigned prefix_bits; } tests[] = { {{0x00000000, 0xffffffff}, {0x00000000, 0xffffffff}, 0}, {{0x00000001, 0xffffffff}, {0x00000001, 0x00000001}, 32}, {{0xffffffff, 0xffffffff}, {0xffffffff, 0xffffffff}, 32}, {{0xfffffffe, 0xfffffffe}, {0xfffffffe, 0xfffffffe}, 32}, {{0x0A000000, 0x0A0000Ff}, {0x0A000000, 0x0A0000ff}, 24}, {{0x0A0000ff, 0x0A0000Ff}, {0x0A0000ff, 0x0A0000ff}, 32}, {{0x0A000000, 0x0A0000Ff}, {0x0A000000, 0x0A0000Ff}, 24}, {{0x0A000001, 0x0A0000Fe}, {0x0A000001, 0x0A000001}, 32}, {{0x0A000008, 0x0A0000Fe}, {0x0A000008, 0x0A00000f}, 29}, {{0x0A000080, 0x0A0000Fe}, {0x0A000080, 0x0A0000bf}, 26}, {{0x0A0000c0, 0x0A0000Fe}, {0x0A0000c0, 0x0A0000df}, 27}, {{0x0A0000c1, 0x0A0000Fe}, {0x0A0000c1, 0x0A0000c1}, 32}, {{0x0A0000fe, 0x0A0000Fe}, {0x0A0000fe, 0x0A0000fe}, 32}, {{0,0}, {0,0}} }; size_t i; for (i=0; tests[i].in.end != 0; i++) { unsigned prefix_bits = 0xFFFFFFFF; struct Range out = range_first_cidr(tests[i].in, &prefix_bits); if (out.begin != tests[i].out.begin || out.end != tests[i].out.end || prefix_bits != tests[i].prefix_bits) { fprintf(stderr, "[%u] 0x%08x->0x%08x /%u 0x%08x->0x%08x /%u\n", (unsigned)i, out.begin, out.end, prefix_bits, tests[i].out.begin, tests[i].out.end, tests[i].prefix_bits); return 1; } } return 0; } /*************************************************************************** * Test if two ranges overlap. * FIXME: I need to change this so that it (a) doesn't trigger on invalid * ranges (those where begin>end) and (b) use a simpler algorithm ***************************************************************************/ static int range_is_overlap(struct Range lhs, struct Range rhs) { if (lhs.begin < rhs.begin) { if (lhs.end == 0xFFFFFFFF || lhs.end + 1 >= rhs.begin) return 1; } if (lhs.begin >= rhs.begin) { if (lhs.end <= rhs.end) return 1; } if (rhs.begin < lhs.begin) { if (rhs.end == 0xFFFFFFFF || rhs.end + 1 >= lhs.begin) return 1; } if (rhs.begin >= lhs.begin) { if (rhs.end <= lhs.end) return 1; } return 0; } /*************************************************************************** * Combine two ranges, such as when they overlap. ***************************************************************************/ static void range_combine(struct Range *lhs, struct Range rhs) { if (lhs->begin > rhs.begin) lhs->begin = rhs.begin; if (lhs->end < rhs.end) lhs->end = rhs.end; } /*************************************************************************** * Callback for qsort() for comparing two ranges ***************************************************************************/ static int range_compare(const void *lhs, const void *rhs) { struct Range *left = (struct Range *)lhs; struct Range *right = (struct Range *)rhs; if (left->begin < right->begin) return -1; else if (left->begin > right->begin) return 1; else return 0; } /*************************************************************************** ***************************************************************************/ static void rangelist_remove_at(struct RangeList *targets, size_t index) { memmove(&targets->list[index], &targets->list[index+1], (targets->count - index) * sizeof(targets->list[index]) ); targets->count--; } /*************************************************************************** ***************************************************************************/ void rangelist_sort(struct RangeList *targets) { size_t i; struct RangeList newlist = {0}; unsigned original_count = targets->count; /* Empty lists are, of course, sorted. We need to set this * to avoid an error later on in the code which asserts that * the lists are sorted */ if (targets->count == 0) { targets->is_sorted = 1; return; } /* If it's already sorted, then skip this */ if (targets->is_sorted) { return; } /* First, sort the list */ LOG(3, "[+] range:sort: sorting...\n"); qsort( targets->list, /* the array to sort */ targets->count, /* number of elements to sort */ sizeof(targets->list[0]), /* size of element */ range_compare); /* Second, combine all overlapping ranges. We do this by simply creating * a new list from a sorted list, so we don't have to remove things in the * middle when collapsing overlapping entries together, which is painfully * slow. */ LOG(3, "[+] range:sort: combining...\n"); for (i=0; i<targets->count; i++) { rangelist_add_range(&newlist, targets->list[i].begin, targets->list[i].end); } LOG(3, "[+] range:sort: combined from %u elements to %u elements\n", original_count, newlist.count); free(targets->list); targets->list = newlist.list; targets->count = newlist.count; newlist.list = 0; LOG(2, "[+] range:sort: done...\n"); targets->is_sorted = 1; } /*************************************************************************** * Add the IPv4 range to our list of ranges. ***************************************************************************/ void rangelist_add_range(struct RangeList *targets, unsigned begin, unsigned end) { struct Range range; range.begin = begin; range.end = end; /* auto-expand the list if necessary */ if (targets->count + 1 >= targets->max) { targets->max = targets->max * 2 + 1; targets->list = REALLOCARRAY(targets->list, targets->max, sizeof(targets->list[0])); } /* If empty list, then add this one */ if (targets->count == 0) { targets->list[0] = range; targets->count++; targets->is_sorted = 1; return; } /* If new range overlaps the last range in the list, then combine it * rather than appending it. This is an optimization for the fact that * we often read in sequential addresses */ if (range_is_overlap(targets->list[targets->count - 1], range)) { range_combine(&targets->list[targets->count - 1], range); targets->is_sorted = 0; return; } /* append to the end of our list */ targets->list[targets->count] = range; targets->count++; targets->is_sorted = 0; } /** Use this when adding TCP ports, to avoid the comoplication of how * ports are stored */ void rangelist_add_range_tcp(struct RangeList *targets, unsigned begin, unsigned end) { rangelist_add_range(targets, Templ_TCP + begin, Templ_TCP + end); } /** Use this when adding UDP ports, to avoid the comoplication of how * ports are stored */ void rangelist_add_range_udp(struct RangeList *targets, unsigned begin, unsigned end) { rangelist_add_range(targets, Templ_UDP + begin, Templ_UDP + end); } /*************************************************************************** * This is the "free" function for the list, freeing up any memory we've * allocated. ***************************************************************************/ void rangelist_remove_all(struct RangeList *targets) { free(targets->list); free(targets->picker); memset(targets, 0, sizeof(*targets)); } /*************************************************************************** ***************************************************************************/ void rangelist_merge(struct RangeList *list1, const struct RangeList *list2) { unsigned i; for (i=0; i<list2->count; i++) { rangelist_add_range(list1, list2->list[i].begin, list2->list[i].end); } rangelist_sort(list1); } /*************************************************************************** * This searches a range list and removes that range of IP addresses, if * they exist. Since the input range can overlap multiple entries, then * more than one entry can be removed, or truncated. Since the range * can be in the middle of an entry in the list, it can actually increase * the list size by one, as that entry is split into two entries. * DEPRECATED: this function is deprecated, and will be removed at some * point. It's only remaining in order to serve as a regression test for * its replacement. ***************************************************************************/ static void rangelist_remove_range(struct RangeList *targets, unsigned begin, unsigned end) { unsigned i; struct Range x; x.begin = begin; x.end = end; /* See if the range overlaps any exist range already in the * list */ for (i = 0; i < targets->count; i++) { if (!range_is_overlap(targets->list[i], x)) continue; /* If the removal-range wholly covers the range, delete * it completely */ if (begin <= targets->list[i].begin && end >= targets->list[i].end) { rangelist_remove_at(targets, i); i--; continue; } /* If the removal-range bisects the target-rage, truncate * the lower end and add a new high-end */ if (begin > targets->list[i].begin && end < targets->list[i].end) { struct Range newrange; newrange.begin = end+1; newrange.end = targets->list[i].end; targets->list[i].end = begin-1; rangelist_add_range(targets, newrange.begin, newrange.end); i--; continue; } /* If overlap on the lower side */ if (end >= targets->list[i].begin && end < targets->list[i].end) { targets->list[i].begin = end+1; } /* If overlap on the upper side */ if (begin > targets->list[i].begin && begin <= targets->list[i].end) { targets->list[i].end = begin-1; } //assert(!"impossible"); } } static void rangelist_add_range2(struct RangeList *targets, struct Range range) { rangelist_add_range(targets, range.begin, range.end); } static void rangelist_remove_range2(struct RangeList *targets, struct Range range) { rangelist_remove_range(targets, range.begin, range.end); } /*************************************************************************** * Parse an IPv4 address from a line of text, moving the offset forward * to the first non-IPv4 character ***************************************************************************/ static int parse_ipv4(const char *line, unsigned *inout_offset, unsigned max, unsigned *ipv4) { unsigned offset = *inout_offset; unsigned result = 0; unsigned i; for (i=0; i<4; i++) { unsigned x = 0; unsigned digits = 0; if (offset >= max) return -4; if (!isdigit(line[offset]&0xFF)) return -1; /* clear leading zeros */ while (offset < max && line[offset] == '0') offset++; /* parse maximum of 3 digits */ while (offset < max && isdigit(line[offset]&0xFF)) { x = x * 10 + (line[offset] - '0'); offset++; if (++digits > 3) return -2; } if (x > 255) return -5; result = result * 256 + (x & 0xFF); if (i == 3) break; if (line[offset] != '.') return -3; offset++; /* skip dot */ } *inout_offset = offset; *ipv4 = result; return 0; /* parse OK */ } /**************************************************************************** * Parse from text an IPv4 address range. This can be in one of several * formats: * - '192.168.1.1" - a single address * - '192.168.1.0/24" - a CIDR spec * - '192.168.1.0-192.168.1.255' - a range * @param line * Part of a line of text, probably read from a commandline or conf * file. * @param inout_offset * On input, the offset from the start of the line where the address * starts. On output, the offset of the first character after the * range, or equal to 'max' if the line prematurely ended. * @param max * The maximum length of the line. * @return * The first and last address of the range, inclusive. ****************************************************************************/ struct Range range_parse_ipv4(const char *line, unsigned *inout_offset, unsigned max) { unsigned offset; struct Range result; static const struct Range badrange = {0xFFFFFFFF, 0}; int err; if (line == NULL) return badrange; if (inout_offset == NULL) { inout_offset = &offset; offset = 0; max = (unsigned)strlen(line); } else offset = *inout_offset; /* trim whitespace */ while (offset < max && isspace(line[offset]&0xFF)) offset++; /* get the first IP address */ err = parse_ipv4(line, &offset, max, &result.begin); if (err) { return badrange; } result.end = result.begin; /* trim whitespace */ while (offset < max && isspace(line[offset]&0xFF)) offset++; /* If only one IP address, return that */ if (offset >= max) goto end; /* * Handle CIDR address of the form "10.0.0.0/8" */ if (line[offset] == '/') { uint64_t prefix = 0; uint64_t mask = 0; unsigned digits = 0; /* skip slash */ offset++; if (!isdigit(line[offset]&0xFF)) { return badrange; } /* strip leading zeroes */ while (offset<max && line[offset] == '0') offset++; /* parse decimal integer */ while (offset<max && isdigit(line[offset]&0xFF)) { prefix = prefix * 10 + (line[offset++] - '0'); if (++digits > 2) return badrange; } if (prefix > 32) return badrange; /* Create the mask from the prefix */ mask = 0xFFFFFFFF00000000ULL >> prefix; /* Mask off any non-zero bits from the start * TODO print warning */ result.begin &= mask; /* Set all suffix bits to 1, so that 192.168.1.0/24 has * an ending address of 192.168.1.255. */ result.end = result.begin | (unsigned)~mask; goto end; } /* * Handle a dashed range like "10.0.0.100-10.0.0.200" */ if (offset<max && line[offset] == '-') { unsigned ip; offset++; err = parse_ipv4(line, &offset, max, &ip); if (err) return badrange; if (ip < result.begin) { result.begin = 0xFFFFFFFF; result.end = 0x00000000; LOG(0, "err: ending addr %u.%u.%u.%u cannot come before starting addr %u.%u.%u.%u\n", ((ip>>24)&0xFF), ((ip>>16)&0xFF), ((ip>>8)&0xFF), ((ip>>0)&0xFF), ((result.begin>>24)&0xFF), ((result.begin>>16)&0xFF), ((result.begin>>8)&0xFF), ((result.begin>>0)&0xFF) ); } else result.end = ip; goto end; } end: *inout_offset = offset; return result; } /*************************************************************************** * This is the old algorithm for applying exclude ranges, very slow * for large lists. We keep it around for verifying correctness of the * new replacement algorithm. ***************************************************************************/ static void rangelist_exclude2( struct RangeList *targets, const struct RangeList *excludes) { unsigned i; for (i=0; i<excludes->count; i++) { struct Range range = excludes->list[i]; rangelist_remove_range(targets, range.begin, range.end); } /* Since chopping up large ranges can split ranges, this can * grow the list so we need to re-sort it */ rangelist_sort(targets); } /** * Applies the (presumably overlapping) exclude range to the target. This can have * four outcomes: * - there is no overlap, in which case 'target' is unchanged, and 'split' * is set to INVALID. * - the entire target is excluded, in which case it's set to INVALID. * - the overlap is at the beginning, in which case the 'begin' is increased. * - the overlap is at the end, in which case 'end' is reduced. * - the overlap is in the middle, in which case the target is split * in two, with 'target' becoming the low addresses, and 'split' becoming * the high addresses. */ static void range_apply_exclude(const struct Range exclude, struct Range *target, struct Range *split) { /* Set 'split' to invalid to start with */ split->begin = 2; split->end = 1; /* Case 1: no overlap */ if (target->begin > exclude.end || target->end < exclude.begin) { return; } /* Case 2: complete overlap, mark target as invalid and return */ if (target->begin >= exclude.begin && target->end <= exclude.end) { target->begin = 2; target->end = 1; return; } /* Case 3: overlap at start */ if (target->begin >= exclude.begin && target->end > exclude.end) { target->begin = exclude.end + 1; return; } /* Case 4: overlap at end */ if (target->begin < exclude.begin && target->end <= exclude.end) { target->end = exclude.begin - 1; return; } /* Case 5: this range needs to be split */ if (target->begin < exclude.begin && target->end > exclude.end) { split->end = target->end; split->begin = exclude.end + 1; target->end = exclude.begin - 1; return; } /* No other condition should be possible */ assert(!"possible"); } /*************************************************************************** ***************************************************************************/ int range_is_valid(struct Range range) { return range.begin <= range.end; } /*************************************************************************** * Apply the exclude ranges, which means removing everything from "targets" * that's also in "exclude". This can make the target list even bigger * as individually excluded address chop up large ranges. ***************************************************************************/ void rangelist_exclude( struct RangeList *targets, struct RangeList *excludes) { unsigned i; unsigned x; struct RangeList newlist = {0}; /* Both lists must be sorted */ rangelist_sort(targets); rangelist_sort(excludes); /* Go through all target ranges, apply excludes to them * (which may split into two ranges), and add them to * the new target list */ x = 0; for (i=0; i<targets->count; i++) { struct Range range = targets->list[i]; /* Move the exclude forward until we find a potentially * overlapping candidate */ while (x < excludes->count && excludes->list[x].end < range.begin) x++; /* Keep applying excludes to this range as long as there are overlaps */ while (x < excludes->count && excludes->list[x].begin <= range.end) { struct Range split = INVALID_RANGE; range_apply_exclude(excludes->list[x], &range, &split); /* If there is a split, then add the original range to our list * and then set that range to the split-ed portion */ if (range_is_valid(split)) { rangelist_add_range(&newlist, range.begin, range.end); memcpy(&range, &split, sizeof(range)); } if (excludes->list[x].begin > range.end) break; x++; } /* If the range hasn't been completely excluded, then add the remnants */ if (range_is_valid(range)) { rangelist_add_range(&newlist, range.begin, range.end); } } /* Now free the old list and move over the new list */ free(targets->list); targets->list = newlist.list; targets->count = newlist.count; newlist.list = NULL; newlist.count = 0; /* Since chopping up large ranges can split ranges, this can * grow the list so we need to re-sort it */ rangelist_sort(targets); } /*************************************************************************** * Counts the total number of addresses in all the ranges combined. * For 0.0.0.0/0, this will be 0x100000000, which means we have to use a * larger number than 32-bit to return the result. This assumes that * all overlaps have been resolved in the list (i.e. it's been sorted). ***************************************************************************/ uint64_t rangelist_count(const struct RangeList *targets) { unsigned i; uint64_t result = 0; for (i=0; i<targets->count; i++) { result += (uint64_t)targets->list[i].end - (uint64_t)targets->list[i].begin + 1UL; } return result; } /*************************************************************************** * Get's the indexed port/address. * * Note that this requires a search of all the ranges. Currently, this is * done by a learn search of the ranges. This needs to change, because * once we start adding in a lot of "exclude ranges", the address space * will get fragmented, and the linear search will take too long. ***************************************************************************/ static unsigned rangelist_pick_linearsearch(const struct RangeList *targets, uint64_t index) { unsigned i; for (i=0; i<targets->count; i++) { uint64_t range = (uint64_t)targets->list[i].end - (uint64_t)targets->list[i].begin + 1UL; if (index < range) return (unsigned)(targets->list[i].begin + index); else index -= range; } assert(!"end of list"); return 0; } /*************************************************************************** ***************************************************************************/ unsigned rangelist_pick(const struct RangeList *targets, uint64_t index) { unsigned maxmax = targets->count; unsigned min = 0; unsigned max = targets->count; unsigned mid; const unsigned *picker = targets->picker; if (!targets->is_sorted) rangelist_sort((struct RangeList *)targets); assert(targets->is_sorted); if (picker == NULL) { /* optimization wasn't done */ return rangelist_pick_linearsearch(targets, index); } for (;;) { mid = min + (max-min)/2; if (index < picker[mid]) { max = mid; continue; } if (index >= picker[mid]) { if (mid + 1 == maxmax) break; else if (index < picker[mid+1]) break; else min = mid+1; } } return (unsigned)(targets->list[mid].begin + (index - picker[mid])); } /*************************************************************************** * The normal "pick" function is a linear search, which is slow when there * are a lot of ranges. Therefore, the "pick2" creates sort of binary * search that'll be a lot faster. We choose "binary search" because * it's the most cache-efficient, having the least overhead to fit within * the cache. ***************************************************************************/ void rangelist_optimize(struct RangeList *targets) { unsigned *picker; unsigned i; unsigned total = 0; if (targets->count == 0) return; /* This technique only works when the targets are in * ascending order */ if (!targets->is_sorted) rangelist_sort(targets); if (targets->picker) free(targets->picker); picker = REALLOCARRAY(NULL, targets->count, sizeof(*picker)); for (i=0; i<targets->count; i++) { picker[i] = total; total += targets->list[i].end - targets->list[i].begin + 1; } targets->picker = picker; } /*************************************************************************** * Provide my own rand() simply to avoid static-analysis warning me that * 'rand()' is unrandom, when in fact we want the non-random properties of * rand() for regression testing. ***************************************************************************/ static unsigned r_rand(unsigned *seed) { static const unsigned a = 214013; static const unsigned c = 2531011; *seed = (*seed) * a + c; return (*seed)>>16 & 0x7fff; } /*************************************************************************** ***************************************************************************/ static int regress_pick2() { unsigned i; unsigned seed = 0; /* * Run 100 randomized regression tests */ for (i=0; i<100; i++) { unsigned j; unsigned num_targets; unsigned begin = 0; unsigned end; struct RangeList targets[1] = {{0}}; struct RangeList duplicate[1] = {{0}}; unsigned range; /* Create a new target list */ memset(targets, 0, sizeof(targets[0])); /* fill the target list with random ranges */ num_targets = r_rand(&seed)%5 + 1; for (j=0; j<num_targets; j++) { begin += r_rand(&seed)%10; end = begin + r_rand(&seed)%10; rangelist_add_range(targets, begin, end); } rangelist_sort(targets); range = (unsigned)rangelist_count(targets); /* Optimize for faster 'picking' addresses from an index */ rangelist_optimize(targets); /* Duplicate the targetlist using the picker */ memset(duplicate, 0, sizeof(duplicate[0])); for (j=0; j<range; j++) { unsigned x; x = rangelist_pick(targets, j); rangelist_add_range(duplicate, x, x); } rangelist_sort(duplicate); /* at this point, the two range lists should be identical */ REGRESS(targets->count == duplicate->count); REGRESS(memcmp(targets->list, duplicate->list, targets->count*sizeof(targets->list[0])) == 0); rangelist_remove_all(targets); rangelist_remove_all(duplicate); } return 0; } /*************************************************************************** * This returns a character pointer where parsing ends so that it can * handle multiple stuff on the same line ***************************************************************************/ const char * rangelist_parse_ports(struct RangeList *ports, const char *string, unsigned *is_error, unsigned proto_offset) { char *p = (char*)string; unsigned tmp = 0; if (is_error == NULL) is_error = &tmp; *is_error = 0; while (*p) { unsigned port; unsigned end; /* skip whitespace */ while (*p && isspace(*p & 0xFF)) p++; /* end at comment */ if (*p == 0 || *p == '#') break; /* special processing. Nmap allows ports to be prefixed with a * characters to clarify TCP, UDP, or SCTP */ if (isalpha(*p&0xFF) && p[1] == ':') { switch (*p) { case 'T': case 't': proto_offset = 0; break; case 'U': case 'u': proto_offset = Templ_UDP; break; case 'S': case 's': proto_offset = Templ_SCTP; break; case 'O': case 'o': proto_offset = Templ_Oproto_first; break; case 'I': case 'i': proto_offset = Templ_ICMP_echo; break; default: LOG(0, "bad port character = %c\n", p[0]); *is_error = 1; return p; } p += 2; } /* * Get the start of the range. */ if (p[0] == '-') { /* nmap style port range spec meaning starting with 0 */ port = 1; } else if (isdigit(p[0] & 0xFF)) { port = (unsigned)strtoul(p, &p, 0); } else { break; } /* * Get the end of the range */ if (*p == '-') { p++; if (!isdigit(*p)) { /* nmap style range spec meaning end with 65535 */ end = (proto_offset == Templ_Oproto_first) ? 0xFF : 0xFFFF; } else { end = (unsigned)strtoul(p, &p, 0); } } else end = port; /* Check for out-of-range */ if (port > 0xFF && proto_offset == Templ_Oproto_first) { *is_error = 2; return p; } else if (port > 0xFFFF || end > 0xFFFF || end < port) { *is_error = 2; return p; } /* Add to our list */ rangelist_add_range(ports, port+proto_offset, end+proto_offset); /* skip trailing whitespace */ while (*p && isspace(*p & 0xFF)) p++; /* Now get the next port/range if there is one */ if (*p != ',') break; p++; } return p; } /*************************************************************************** * Deterministic random number generator for repeatable tests. ***************************************************************************/ static unsigned lcgrand(unsigned *state) { *state = 1103515245 * (*state) + 12345; return *state; } /*************************************************************************** * Create an exact duplicate range. ***************************************************************************/ static void rangelist_copy(struct RangeList *dst, const struct RangeList *src) { free(dst->list); free(dst->picker); memset(dst, 0, sizeof(*dst)); dst->list = CALLOC(src->count, sizeof(src->list[0])); memcpy(dst->list, src->list, src->count * sizeof(src->list[0])); dst->count = src->count; dst->max = dst->count; dst->is_sorted = src->is_sorted; } /*************************************************************************** * Test if two ranges are exact duplicates * @return true if equal, false if not equal ***************************************************************************/ static bool rangelist_is_equal(const struct RangeList *lhs, const struct RangeList *rhs) { unsigned i; if (lhs->count != rhs->count) return false; for (i=0; i<lhs->count; i++) { if (lhs->list[i].begin != rhs->list[i].begin) { return false; } if (lhs->list[i].end != rhs->list[i].end) { return false; } } return true; } /*************************************************************************** * The old way of excluding addresses assume unsorted lists, so had to * search the entire exclude list for each included address, which is * O(n * m), and fails when we have millions of excludes and includes, * because it takes forever to apply. * This was revamped with a new version that sorts both lists first, * the applies the excludes sequentially in an O(n + m) operation. * This selftest simply creates random lists and runs the new code * against the old code, and make sure the results match. ***************************************************************************/ static int exclude_selftest(void) { unsigned seed = 0; struct RangeList includes1 = {0}; struct RangeList includes2 = {0}; struct RangeList excludes = {0}; unsigned addr = 0; size_t i; /* In my initial tests, simply using 10 as the count seems to * catch all the combinations. On the other hand, 100,000 takes * a long time to complete, because it's O(n2) quadratic time. * Therefore, I pick a thousand as a compromise, likely to catch * any possibility, yet fast enough to complete quickly even on * a Raspberry Pi */ static const unsigned MAXCOUNT = 1000; /* Fill the include list. This is designed to make short ranges * that are a short distance apart. We'll do the same for the * same for the excludes, using a different random seed. This * should create two lists that have lots and lots of overlapping * and non-overlapping ranges. */ seed = 0; addr = 0; for (i=0; i<MAXCOUNT; i++) { unsigned begin; unsigned end; addr += lcgrand(&seed) & 0xF; begin = addr; addr += lcgrand(&seed) & 0xF; end = addr; rangelist_add_range(&includes1, begin, end); } rangelist_sort(&includes1); /* Fill the exclude list, using the same algorithm as above for * includes, but now with a different seed. This creates lots of * conflicts. */ seed = 1; addr = 0; for (i=0; i<MAXCOUNT; i++) { unsigned begin; unsigned end; addr += lcgrand(&seed) & 0xF; begin = addr; addr += lcgrand(&seed) & 0xF; end = addr; rangelist_add_range(&excludes, begin, end); } rangelist_sort(&excludes); /* Now create a copy of the include list, because we want to * apply excludes using two different algorithms to see if the * results match */ rangelist_copy(&includes2, &includes1); if (!rangelist_is_equal(&includes1, &includes2)) return 1; /* Now apply the exclude algorithms, both new and old, to * the include lists. */ rangelist_exclude(&includes1, &excludes); rangelist_exclude2(&includes2, &excludes); if (!rangelist_is_equal(&includes1, &includes2)) return 1; /* fail */ /* If we reach this point, the selftest has succeeded */ return 0; } /*************************************************************************** * Called during "make test" to run a regression test over this module. ***************************************************************************/ int ranges_selftest(void) { struct Range r; struct RangeList targets[1] = {{0}}; REGRESS(regress_pick2() == 0); /* Do a separate test of the 'exclude' feature */ if (exclude_selftest()) return 1; memset(targets, 0, sizeof(targets[0])); #define ERROR() LOG(0, "selftest: failed %s:%u\n", __FILE__, __LINE__); /* test for the /0 CIDR block, since we'll be using that a lot to scan the entire * Internet */ r = range_parse_ipv4("0.0.0.0/0", 0, 0); REGRESS(r.begin == 0 && r.end == 0xFFFFFFFF); r = range_parse_ipv4("0.0.0./0", 0, 0); REGRESS(r.begin > r.end); r = range_parse_ipv4("75.748.86.91", 0, 0); REGRESS(r.begin > r.end); r = range_parse_ipv4("23.75.345.200", 0, 0); REGRESS(r.begin > r.end); r = range_parse_ipv4("192.1083.0.1", 0, 0); REGRESS(r.begin > r.end); r = range_parse_ipv4("192.168.1.3", 0, 0); if (r.begin != 0xc0a80103 || r.end != 0xc0a80103) { LOG(0, "r.begin = 0x%08x r.end = 0x%08x\n", r.begin, r.end); ERROR(); return 1; } r = range_parse_ipv4("10.0.0.20-10.0.0.30", 0, 0); if (r.begin != 0x0A000000+20 || r.end != 0x0A000000+30) { LOG(0, "r.begin = 0x%08x r.end = 0x%08x\n", r.begin, r.end); ERROR(); return 1; } r = range_parse_ipv4("10.0.1.2/16", 0, 0); if (r.begin != 0x0A000000 || r.end != 0x0A00FFFF) { LOG(0, "r.begin = 0x%08x r.end = 0x%08x\n", r.begin, r.end); ERROR(); return 1; } rangelist_add_range2(targets, range_parse_ipv4("10.0.0.0/24", 0, 0)); rangelist_add_range2(targets, range_parse_ipv4("10.0.1.10-10.0.1.19", 0, 0)); rangelist_add_range2(targets, range_parse_ipv4("10.0.1.20-10.0.1.30", 0, 0)); rangelist_add_range2(targets, range_parse_ipv4("10.0.0.0-10.0.1.12", 0, 0)); rangelist_sort(targets); if (targets->count != 1) { LOG(0, "count = %u\n", targets->count); ERROR(); return 1; } if (targets->list[0].begin != 0x0a000000 || targets->list[0].end != 0x0a000100+30) { LOG(0, "r.begin = 0x%08x r.end = 0x%08x\n", targets->list[0].begin, targets->list[0].end); ERROR(); return 1; } rangelist_remove_all(targets); /* * Test removal */ memset(targets, 0, sizeof(targets[0])); rangelist_add_range2(targets, range_parse_ipv4("10.0.0.0/8", 0, 0)); rangelist_sort(targets); /* These removals shouldn't change anything */ rangelist_remove_range2(targets, range_parse_ipv4("9.255.255.255", 0, 0)); rangelist_remove_range2(targets, range_parse_ipv4("11.0.0.0/16", 0, 0)); rangelist_remove_range2(targets, range_parse_ipv4("192.168.0.0/16", 0, 0)); rangelist_sort(targets); if (targets->count != 1 || targets->list->begin != 0x0a000000 || targets->list->end != 0x0aFFFFFF) { ERROR(); return 1; } /* These removals should remove a bit from the edges */ rangelist_remove_range2(targets, range_parse_ipv4("1.0.0.0-10.0.0.0", 0, 0)); rangelist_remove_range2(targets, range_parse_ipv4("10.255.255.255-11.0.0.0", 0, 0)); rangelist_sort(targets); if (targets->count != 1 || targets->list->begin != 0x0a000001 || targets->list->end != 0x0aFFFFFE) { ERROR(); return 1; } /* remove things from the middle */ rangelist_remove_range2(targets, range_parse_ipv4("10.10.0.0/16", 0, 0)); rangelist_remove_range2(targets, range_parse_ipv4("10.20.0.0/16", 0, 0)); rangelist_sort(targets); if (targets->count != 3) { ERROR(); return 1; } rangelist_remove_range2(targets, range_parse_ipv4("10.12.0.0/16", 0, 0)); rangelist_sort(targets); if (targets->count != 4) { ERROR(); return 1; } rangelist_remove_range2(targets, range_parse_ipv4("10.10.10.10-10.12.12.12", 0, 0)); rangelist_sort(targets); if (targets->count != 3) { ERROR(); return 1; } rangelist_remove_all(targets); /* test ports */ { unsigned is_error = 0; memset(targets, 0, sizeof(targets[0])); rangelist_parse_ports(targets, "80,1000-2000,1234,4444", &is_error, 0); rangelist_sort(targets); if (targets->count != 3 || is_error) { ERROR(); return 1; } if (targets->list[0].begin != 80 || targets->list[0].end != 80 || targets->list[1].begin != 1000 || targets->list[1].end != 2000 || targets->list[2].begin != 4444 || targets->list[2].end != 4444) { ERROR(); return 1; } } if (selftest_range_first_cidr() != 0) { ERROR(); return 1; } return 0; }
44,492
C
.c
1,167
31.437875
120
0.539044
robertdavidgraham/masscan
23,250
3,042
399
AGPL-3.0
9/7/2024, 9:40:14 AM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
5,399
misc-rstfilter.h
robertdavidgraham_masscan/src/misc-rstfilter.h
/* RST filter In theory, we should transmit a RST packet every time we receive an invalid TCP packet. In practice, this can lead to endless transmits when the other size continues to transmit bad packets. This may happen accidentally, or this may happen on purpose from the other side trying to attack the scanner intentionally. In May 2019 I see this from somebody who I suspect is trying to do that, replying back as fast as the scanner transmits (when running at 10,000 packets per-second). This halts the scan, as it's throttle limit is filled sending RSTs and not doing something useful. The design is a simple non-deterministic algorithm. It hashes the IP/prot combo, then updates a counter at that bucket. When it reaches its limit, it stops transmitting resets. However, it'll also slowly empty buckets, so can occasionally transmit a RST now and then. */ #ifndef MISC_RSTFILTER_H #define MISC_RSTFILTER_H #include <stdio.h> #include "massip-addr.h" struct ResetFilter; /** * Create a structure for this. * @param seed * A random seed chosen via entropy at startup, so that adversaries * can't predict where the buckets will be. * @param bucket_count * The number of buckets. This'll be rounded up to the nearest * power-of-two. 16384 is probably a good number. * @return an instance of this object that should be eventually * cleaned up with 'rstfilter_destroy()'. */ struct ResetFilter * rstfilter_create(unsigned long long seed, size_t bucket_count); /** * Cleans up the object that was created with 'rstfilter_create()'. */ void rstfilter_destroy(struct ResetFilter *rf); /** * Tests to see if we should ignore the given RST packet. This will * also slowly empty a random bucket * @return 1 if we should filter out the offending packet and ignore it, * or else 0 if we shouldn't ignore it. */ int rstfilter_is_filter(struct ResetFilter *rf, ipaddress src_ip, unsigned src_port, ipaddress dst_ip, unsigned dst_port); int rstfilter_selftest(void); #endif
2,043
C
.c
49
39.795918
118
0.76426
robertdavidgraham/masscan
23,250
3,042
399
AGPL-3.0
9/7/2024, 9:40:14 AM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
5,401
proto-oproto.c
robertdavidgraham_masscan/src/proto-oproto.c
#include "proto-oproto.h" #include "unusedparm.h" void handle_oproto(struct Output *out, time_t timestamp, const unsigned char *px, unsigned length, struct PreprocessedInfo *parsed, uint64_t entropy) { UNUSEDPARM(entropy); UNUSEDPARM(parsed); UNUSEDPARM(length); UNUSEDPARM(px); UNUSEDPARM(timestamp); UNUSEDPARM(out); }
388
C
.c
15
20.4
55
0.672043
robertdavidgraham/masscan
23,250
3,042
399
AGPL-3.0
9/7/2024, 9:40:14 AM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
5,402
proto-udp.c
robertdavidgraham_masscan/src/proto-udp.c
#include "proto-udp.h" #include "proto-coap.h" #include "proto-dns.h" #include "proto-isakmp.h" #include "proto-netbios.h" #include "proto-snmp.h" #include "proto-memcached.h" #include "proto-ntp.h" #include "proto-zeroaccess.h" #include "proto-preprocess.h" #include "syn-cookie.h" #include "util-logger.h" #include "output.h" #include "masscan-status.h" #include "unusedparm.h" /**************************************************************************** * When the "--banner" command-line option is selected, this will * will take up to 64 bytes of a response and display it. Other UDP * protocol parsers may also default to this function when they detect * a response is not the protocol they expect. For example, if a response * to port 161 obviously isn't ASN.1 formatted, the SNMP parser will * call this function instead. In such cases, the protocool identifier will * be [unknown] rather than [snmp]. ****************************************************************************/ unsigned default_udp_parse(struct Output *out, time_t timestamp, const unsigned char *px, unsigned length, struct PreprocessedInfo *parsed, uint64_t entropy) { ipaddress ip_them = parsed->src_ip; unsigned port_them = parsed->port_src; UNUSEDPARM(entropy); if (length > 64) length = 64; output_report_banner( out, timestamp, ip_them, 17, port_them, PROTO_NONE, parsed->ip_ttl, px, length); return 0; } /**************************************************************************** ****************************************************************************/ void handle_udp(struct Output *out, time_t timestamp, const unsigned char *px, unsigned length, struct PreprocessedInfo *parsed, uint64_t entropy) { ipaddress ip_them = parsed->src_ip; unsigned port_them = parsed->port_src; unsigned status = 0; /* Report "open" status regardless */ output_report_status( out, timestamp, PortStatus_Open, ip_them, 17, /* ip proto = udp */ port_them, 0, parsed->ip_ttl, parsed->mac_src); switch (port_them) { case 53: /* DNS - Domain Name System (amplifier) */ status = handle_dns(out, timestamp, px, length, parsed, entropy); break; case 123: /* NTP - Network Time Protocol (amplifier) */ status = ntp_handle_response(out, timestamp, px, length, parsed, entropy); break; case 137: /* NetBIOS (amplifier) */ status = handle_nbtstat(out, timestamp, px, length, parsed, entropy); break; case 161: /* SNMP - Simple Network Managment Protocol (amplifier) */ status = handle_snmp(out, timestamp, px, length, parsed, entropy); break; case 500: /* ISAKMP - IPsec key negotiation */ status = isakmp_parse(out, timestamp, px + parsed->app_offset, parsed->app_length, parsed, entropy); break; case 5683: status = coap_handle_response(out, timestamp, px + parsed->app_offset, parsed->app_length, parsed, entropy); break; case 11211: /* memcached (amplifier) */ px += parsed->app_offset; length = parsed->app_length; status = memcached_udp_parse(out, timestamp, px, length, parsed, entropy); break; case 16464: case 16465: case 16470: case 16471: status = handle_zeroaccess(out, timestamp, px, length, parsed, entropy); break; default: px += parsed->app_offset; length = parsed->app_length; status = default_udp_parse(out, timestamp, px, length, parsed, entropy); break; } /* Report banner if some parser didn't already do so. * Also report raw dump if `--rawudp` specified on the * command-line, even if a protocol above already created a more detailed * banner. */ if (status == 0 || out->is_banner_rawudp) { output_report_banner( out, timestamp, ip_them, 17, /* ip proto = udp */ port_them, PROTO_NONE, parsed->ip_ttl, px + parsed->app_offset, parsed->app_length); } }
4,814
C
.c
119
29.579832
94
0.518201
robertdavidgraham/masscan
23,250
3,042
399
AGPL-3.0
9/7/2024, 9:40:14 AM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
5,403
stack-src.c
robertdavidgraham_masscan/src/stack-src.c
#include "stack-src.h" int is_myself(const struct stack_src_t *src, ipaddress ip, unsigned port) { return is_my_ip(src, ip) && is_my_port(src, port); } int is_my_ip(const struct stack_src_t *src, ipaddress ip) { switch (ip.version) { case 4: return src->ipv4.first <= ip.ipv4 && ip.ipv4 <= src->ipv4.last; case 6: return src->ipv6.first.hi == ip.ipv6.hi && src->ipv6.first.lo == ip.ipv6.lo; default: return 0; } } int is_my_port(const struct stack_src_t *src, unsigned port) { return src->port.first <= port && port <= src->port.last; }
592
C
.c
20
25.85
84
0.634446
robertdavidgraham/masscan
23,250
3,042
399
AGPL-3.0
9/7/2024, 9:40:14 AM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
5,404
templ-nmap-payloads.c
robertdavidgraham_masscan/src/templ-nmap-payloads.c
#include "templ-nmap-payloads.h" #include "massip-port.h" #include "massip-rangesv4.h" #include <string.h> #include <ctype.h> #include <stdlib.h> /*************************************************************************** * remove leading/trailing whitespace ***************************************************************************/ static void trim(char *line, size_t sizeof_line) { if (sizeof_line > strlen(line)) sizeof_line = strlen(line); while (isspace(*line & 0xFF)) memmove(line, line+1, sizeof_line--); while (isspace(line[sizeof_line-1] & 0xFF)) line[--sizeof_line] = '\0'; } /*************************************************************************** ***************************************************************************/ static int is_comment(const char *line) { if (line[0] == '#' || line[0] == '/' || line[0] == ';') return 1; else return 0; } /*************************************************************************** ***************************************************************************/ static char * get_next_line(FILE *fp, unsigned *line_number, char *line, size_t sizeof_line) { if (line[0] != '\0') return line; for (;;) { char *p; p = fgets(line, (unsigned)sizeof_line, fp); if (p == NULL) { line[0] = '\0'; return NULL; } (*line_number)++; trim(line, sizeof_line); if (is_comment(line)) continue; if (line[0] == '\0') continue; return line; } } /*************************************************************************** ***************************************************************************/ static void append_byte(unsigned char *buf, size_t *buf_length, size_t buf_max, unsigned c) { if (*buf_length < buf_max) buf[(*buf_length)++] = (unsigned char)c; } /*************************************************************************** ***************************************************************************/ static int isodigit(int c) { if ('0' <= c && c <= '7') return 1; else return 0; } /*************************************************************************** ***************************************************************************/ static unsigned hexval(unsigned c) { if ('0' <= c && c <= '9') return c - '0'; if ('a' <= c && c <= 'f') return c - 'a' + 10; if ('A' <= c && c <= 'F') return c - 'A' + 10; return 0; } /*************************************************************************** ***************************************************************************/ static const char * parse_c_string(unsigned char *buf, size_t *buf_length, size_t buf_max, const char *line) { size_t offset; if (*line != '\"') return line; else offset = 1; while (line[offset] && line[offset] != '\"') { if (line[offset] == '\\') { offset++; switch (line[offset]) { case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': { unsigned val = 0; if (isodigit(line[offset])) val = val * 8 + hexval(line[offset++]); if (isodigit(line[offset])) val = val * 8 + hexval(line[offset++]); if (isodigit(line[offset])) val = val * 8 + hexval(line[offset++]); append_byte(buf, buf_length, buf_max, val); continue; } break; case 'x': offset++; { unsigned val = 0; if (isxdigit(line[offset])) val = val * 16 + hexval(line[offset++]); if (isxdigit(line[offset])) val = val * 16 + hexval(line[offset++]); append_byte(buf, buf_length, buf_max, val); continue; } break; case 'a': append_byte(buf, buf_length, buf_max, '\a'); break; case 'b': append_byte(buf, buf_length, buf_max, '\b'); break; case 'f': append_byte(buf, buf_length, buf_max, '\f'); break; case 'n': append_byte(buf, buf_length, buf_max, '\n'); break; case 'r': append_byte(buf, buf_length, buf_max, '\r'); break; case 't': append_byte(buf, buf_length, buf_max, '\t'); break; case 'v': append_byte(buf, buf_length, buf_max, '\v'); break; default: case '\\': append_byte(buf, buf_length, buf_max, line[offset]); break; } } else append_byte(buf, buf_length, buf_max, line[offset]); offset++; } if (line[offset] == '\"') offset++; return line + offset; } /*************************************************************************** * Called during processing of the "--nmap-payloads <filename>" directive. ***************************************************************************/ void read_nmap_payloads(FILE *fp, const char *filename, struct PayloadsUDP *payloads, payloads_datagram_add_cb add_payload ) { char line[16384]; unsigned line_number = 0; line[0] = '\0'; for (;;) { unsigned is_error = 0; const char *p; struct RangeList ports[1] = {{0}}; unsigned source_port = 0x10000; unsigned char buf[1500] = {0}; size_t buf_length = 0; memset(ports, 0, sizeof(ports[0])); /* [UDP] */ if (!get_next_line(fp, &line_number, line, sizeof(line))) break; if (memcmp(line, "udp", 3) != 0) { fprintf(stderr, "%s:%u: syntax error, expected \"udp\".\n", filename, line_number); goto end; } else memmove(line, line+3, strlen(line)); trim(line, sizeof(line)); /* [ports] */ if (!get_next_line(fp, &line_number, line, sizeof(line))) break; p = rangelist_parse_ports(ports, line, &is_error, 0); if (is_error) { fprintf(stderr, "%s:%u: syntax error, expected ports\n", filename, line_number); goto end; } memmove(line, p, strlen(p)+1); trim(line, sizeof(line)); /* [C string] */ for (;;) { trim(line, sizeof(line)); if (!get_next_line(fp, &line_number, line, sizeof(line))) break; if (line[0] != '\"') break; p = parse_c_string(buf, &buf_length, sizeof(buf), line); memmove(line, p, strlen(p)+1); trim(line, sizeof(line)); } /* [source] */ if (memcmp(line, "source", 6) == 0) { memmove(line, line+6, strlen(line+5)); trim(line, sizeof(line)); if (!isdigit(line[0])) { fprintf(stderr, "%s:%u: expected source port\n", filename, line_number); goto end; } source_port = (unsigned)strtoul(line, 0, 0); line[0] = '\0'; } /* * Now we've completely parsed the record, so add it to our * list of payloads */ if (buf_length) add_payload(payloads, buf, buf_length, ports, source_port); rangelist_remove_all(ports); } end: ;//fclose(fp); } /**************************************************************************** ****************************************************************************/ int templ_nmap_selftest(void) { unsigned char buf[1024]; size_t buf_length; buf_length = 0; parse_c_string(buf, &buf_length, sizeof(buf), "\"\\t\\n\\r\\x1f\\123\""); if (memcmp(buf, "\t\n\r\x1f\123", 5) != 0) return 1; return 0; /* "OPTIONS sip:[email protected] SIP/2.0\r\n" "Via: SIP/2.0/UDP pc33.atlanta.com;branch=z9hG4bKhjhs8ass877\r\n" "Max-Forwards: 70\r\n" "To: <sip:[email protected]>\r\n" "From: Alice <sip:[email protected]>;tag=1928301774\r\n" "Call-ID: a84b4c76e66710\r\n" "CSeq: 63104 OPTIONS\r\n" "Contact: <sip:[email protected]>\r\n" "Accept: application/sdp\r\n" "Content-Length: 0\r\n" */ }
8,977
C
.c
258
25.077519
79
0.394142
robertdavidgraham/masscan
23,250
3,042
399
AGPL-3.0
9/7/2024, 9:40:14 AM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
5,405
stack-src.h
robertdavidgraham_masscan/src/stack-src.h
#ifndef STACK_SOURCE_H #define STACK_SOURCE_H #include "massip-addr.h" /** * These the source IP addresses that we'll be spoofing. IP addresses * and port numbers come from this list. */ struct stack_src_t { struct { unsigned first; unsigned last; unsigned range; } ipv4; struct { unsigned first; unsigned last; unsigned range; } port; struct { ipv6address first; ipv6address last; unsigned range; } ipv6; }; int is_myself(const struct stack_src_t *src, ipaddress ip, unsigned port); int is_my_ip(const struct stack_src_t *src, ipaddress ip); int is_my_port(const struct stack_src_t *src, unsigned ip); #endif
716
C
.c
29
20.034483
74
0.664706
robertdavidgraham/masscan
23,250
3,042
399
AGPL-3.0
9/7/2024, 9:40:14 AM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
5,407
util-errormsg.c
robertdavidgraham_masscan/src/util-errormsg.c
#include "util-errormsg.h" #include "crypto-siphash24.h" #include "massip-addr.h" #include <stdarg.h> #include <stdio.h> #ifdef _MSC_VER #pragma warning(disable: 4204) #endif static unsigned long long _entropy; void errmsg_init(unsigned long long in_entropy) { _entropy = in_entropy; } static void _errmsg(const char *fmt, va_list marker) { fprintf(stderr, "[-] ERR: "); vfprintf(stderr, fmt, marker); fflush(stderr); } static void _errmsgip(ipaddress ip, unsigned port, const char *fmt, va_list marker) { ipaddress_formatted_t fmted = ipaddress_fmt(ip); fprintf(stderr, "[-] %s:%u: ", fmted.string, port); vfprintf(stderr, fmt, marker); fflush(stderr); } /*************************************************************************** * Prints the message if the global "verbosity" flag exceeds this level. ***************************************************************************/ void ERRMSG(const char *fmt, ...) { va_list marker; size_t index; uint64_t key[2] = {_entropy, _entropy}; static size_t _table[1024] = {0}; /* Hash the address of the format string */ index = (size_t)siphash24(fmt, sizeof(fmt), key); index %= 1024; /* Filter out this error if we've seen it before */ if (_table[index] == (size_t)fmt) return; else _table[index] = (size_t)fmt; va_start(marker, fmt); _errmsg(fmt, marker); va_end(marker); } void ERRMSGip(ipaddress ip, unsigned port, const char *fmt, ...) { va_list marker; size_t index; uint64_t key[2] = {_entropy, _entropy}; static size_t _table[1024] = {0}; /* Hash the address of the format string */ index = (size_t)siphash24(fmt, sizeof(fmt), key); index %= 1024; /* Filter out this error if we've seen it before */ if (_table[index] == (size_t)fmt) return; else _table[index] = (size_t)fmt; va_start(marker, fmt); _errmsgip(ip, port, fmt, marker); va_end(marker); }
2,003
C
.c
68
25.544118
77
0.597798
robertdavidgraham/masscan
23,250
3,042
399
AGPL-3.0
9/7/2024, 9:40:14 AM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
5,409
proto-mc.h
robertdavidgraham_masscan/src/proto-mc.h
#ifndef PROTO_MC_H #define PROTO_MC_H #include "proto-banner1.h" #include "util-bool.h" extern struct ProtocolParserStream banner_mc; #endif
143
C
.c
6
22.5
45
0.807407
robertdavidgraham/masscan
23,250
3,042
399
AGPL-3.0
9/7/2024, 9:40:14 AM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
5,410
templ-tcp-hdr.c
robertdavidgraham_masscan/src/templ-tcp-hdr.c
/* This module edits an existing TCP packet, adding and removing options, setting the values of certain fields. From RFC793: 0 1 2 3 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Source Port | Destination Port | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Sequence Number | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Acknowledgment Number | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Data | |U|A|P|R|S|F| | | Offset| Reserved |R|C|S|S|Y|I| Window | | | |G|K|H|T|N|N| | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Checksum | Urgent Pointer | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Options | Padding | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | data | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ TCP Window Scale Option (WSopt): Kind: 3 Length: 3 bytes +---------+---------+---------+ | Kind=3 |Length=3 |shift.cnt| +---------+---------+---------+ TCP Timestamps Option (TSopt): Kind: 8 Length: 10 bytes +-------+-------+---------------------+---------------------+ |Kind=8 | 10 | TS Value (TSval) |TS Echo Reply (TSecr)| +-------+-------+---------------------+---------------------+ 1 1 4 4 TCP Sack-Permitted Option: Kind: 4 +---------+---------+ | Kind=4 | Length=2| +---------+---------+ TCP SACK Option: Kind: 5 Length: Variable +--------+--------+ | Kind=5 | Length | +--------+--------+--------+--------+ | Left Edge of 1st Block | +--------+--------+--------+--------+ | Right Edge of 1st Block | +--------+--------+--------+--------+ | | / . . . / | | +--------+--------+--------+--------+ | Left Edge of nth Block | +--------+--------+--------+--------+ | Right Edge of nth Block | +--------+--------+--------+--------+ */ #include "templ-tcp-hdr.h" #include "templ-opts.h" #include "util-logger.h" #include "proto-preprocess.h" #include <string.h> #include <stdlib.h> #include <ctype.h> struct tcp_opt_t { const unsigned char *buf; size_t length; unsigned kind; bool is_found; }; struct tcp_hdr_t { size_t begin; size_t max; size_t ip_offset; unsigned char ip_version; bool is_found; }; /** * Do a memmove() of a chunk of memory within a buffer with bounds checking. */ static void safe_memmove(unsigned char *buf, size_t length, size_t to, size_t from, size_t chunklength) { if (chunklength + to > length) { fprintf(stderr, "+"); fflush(stderr); chunklength = length - to; } if (chunklength + from > length) { fprintf(stderr, "-"); fflush(stderr); chunklength = length - from; } memmove(buf + to, buf + from, chunklength); } /** * Do a memset() of a chunk of memory within a buffer with bounds checking */ static void safe_memset(unsigned char *buf, size_t length, size_t offset, int c, size_t chunklength) { if (chunklength + offset > length) { chunklength = length - offset; fprintf(stderr, "*"); fflush(stderr); } memset(buf + offset, c, chunklength); } /*************************************************************************** * A typical hexdump function, but dumps specifically the <options-list> * section of a TCP header. An added feature is that it marks the byte * at "offset". This makes debugging easier, so I can see the <options-list> * as I'm stepping through code. You'll see this commented-out throughout * the code. ***************************************************************************/ static void _HEXDUMP(const void *v, struct tcp_hdr_t hdr, size_t offset, const char *name) { const unsigned char *p = ((const unsigned char *)v) + hdr.begin + 20; size_t i; size_t len = hdr.max - hdr.begin + 8 - 20; printf("%s:\n", name); offset -= hdr.begin + 20; for (i=0; i<len; i += 16) { size_t j; for (j=i; j<i+16 && j<len; j++) { char c = ' '; if (j == offset) c = '>'; if (j + 1 == offset) c = '<'; printf("%02x%c", p[j], c); } for (;j<i+16; j++) printf(" "); printf(" "); for (j=i; j<i+16 && j<len; j++) { char c = p[j]; if (j == offset) c = '#'; if (isprint(c&0xff) && !isspace(c&0xff)) printf("%c", c); else printf("."); } printf("\n"); } } /*************************************************************************** * A quick macro to calculate the TCP header length, given a buffer * and an offset to the start of the TCP header. ***************************************************************************/ static unsigned inline _tcp_header_length(const unsigned char *buf, size_t offset) { return (buf[offset + 12] >> 4) * 4; } /*************************************************************************** * Does a consistency check of the whole packet, including IP header, * TCP header, and the options in the <options-list> field. This is used * in the self-test feature after test cases, to make sure the packet * hasn't bee corrupted. ***************************************************************************/ static int _consistancy_check(const unsigned char *buf, size_t length, const void *payload, size_t payload_length) { struct PreprocessedInfo parsed; unsigned is_success; /* Parse the packet */ is_success = preprocess_frame(buf, (unsigned)length, 1 /*enet*/, &parsed); if (!is_success || parsed.found != FOUND_TCP) { fprintf(stderr, "[-] check: TCP header not found\n"); goto fail; } /* Check the lengths */ switch (parsed.ip_version) { case 4: if (parsed.ip_length + 14 != length) { fprintf(stderr, "[-] check: IP length bad\n"); goto fail; } break; case 6: break; default: fprintf(stderr, "[-] check: IPv?\n"); goto fail; } /* Validate TCP header options */ { size_t offset = parsed.transport_offset; size_t max = offset + _tcp_header_length(buf, offset); /* Get the start of the <options> section of the header. This is defined * as 20 bytes into the TCP header. */ offset += 20; /* Enumerate any existing options one-by-one. */ while (offset < max) { unsigned kind; unsigned len; /* Get the option type (aka. "kind") */ kind = buf[offset++]; if (kind == 0x00) { /* EOL - end of options list * According to the spec, processing should stop here, even if * there are additional options after this point. */ break; } else if (kind == 0x01) { /* NOP - No-operation * This is a single byte option, used to pad other options to * even 4 byte boundaries. Padding is optional. */ continue; } /* If we've reached the end of */ if (offset > max) goto fail; if (offset == max) break; len = buf[offset++]; /* Check for corruption, the lenth field is inclusive, so should * equal at least two. It's maximum length should be bfore the end * of the packet */ if (len < 2 || len > (max-offset+2)) { goto fail; } offset += len - 2; } } /* Check the payload */ if (parsed.app_length != payload_length) goto fail; if (memcmp(buf + parsed.app_offset, payload, payload_length) != 0) goto fail; return 0; fail: return 1; } /*************************************************************************** * Find the TCP header in the packet. We can't be sure what's in the * current template because it could've been provided by the user, so * we instead parse it as if we've received it from the network wire. ***************************************************************************/ static struct tcp_hdr_t _find_tcp_header(const unsigned char *buf, size_t length) { struct tcp_hdr_t hdr = {0}; struct PreprocessedInfo parsed; unsigned is_success; /* * Parse the packet, telling us where the TCP header is. This works * for both IPv4 and IPv6, we care only about the TCP header portion. */ is_success = preprocess_frame(buf, /* the packet, including Ethernet hdr */ (unsigned)length, 1 /*enet*/, &parsed); if (!is_success || parsed.found != FOUND_TCP) { /* We were unable to parse a well-formatted TCP packet. This * might've been UDP or something. */ goto fail; } hdr.begin = parsed.transport_offset; hdr.max = hdr.begin + _tcp_header_length(buf, hdr.begin); hdr.ip_offset = parsed.ip_offset; hdr.ip_version = (unsigned char)parsed.ip_version; hdr.is_found = true; return hdr; fail: hdr.is_found = false; return hdr; } /*************************************************************************** * A quick macro at the start of for(;;) loops that enumerate all the * options in the <option-list> ***************************************************************************/ static inline size_t _opt_begin(struct tcp_hdr_t hdr) { return hdr.begin + 20; /* start of <options> field */ } /*************************************************************************** * A quick macro in the for(;;) loop that enumerates all the options * in the <option-list>. It has three possibilities based on the KIND: * 0x00 - we've reached the end of the options-list * 0x01 - padding NOP byte, which we skipo * 0x?? - some option, the following byte is the length. We skip * that `len` bytes. ***************************************************************************/ static inline size_t _opt_next(struct tcp_hdr_t hdr, size_t offset, const unsigned char *buf) { unsigned kind = buf[offset]; if (kind == 0x00) { return hdr.max; } else if (kind == 0x01) { return offset + 1; } else if (offset + 2 > hdr.max) { return hdr.max; /* corruption */ } else { unsigned len = buf[offset+1]; if (len < 2 || offset + len > hdr.max) return hdr.max; /* corruption */ else return offset + len; } } /*************************************************************************** ***************************************************************************/ static void _HEXDUMPopt(const unsigned char *buf, size_t length, const char *name) { struct tcp_hdr_t hdr; hdr = _find_tcp_header(buf, length); if (!hdr.is_found) { fprintf(stderr, "[-] templ.tcp.hdr: failure\n"); } _HEXDUMP(buf, hdr, _opt_begin(hdr), name); } /*************************************************************************** * Search throgh the <option-list> until we find the specified option, * 'kind', or reach the end of the list. An impossible 'kind', like 0x100, * will force finding the end of the list before padding starts. ***************************************************************************/ static size_t _find_opt(const unsigned char *buf, struct tcp_hdr_t hdr, unsigned in_kind, unsigned *nop_count) { size_t offset; /* This field is optional, if used, set it to zero */ if (nop_count) *nop_count = 0; /* enumerate all <options> looking for a match */ for (offset = _opt_begin(hdr); offset < hdr.max; offset = _opt_next(hdr, offset, buf)) { unsigned kind; /* get the option type/kind */ kind = buf[offset]; /* Stop search if we hit an EOL marker */ if (kind == 0x00) break; /* Stop search when we find our option */ if (kind == in_kind) break; /* Count the number of NOPs leading up to where we end */ if (nop_count) { if (kind == 0x01) (*nop_count)++; else (*nop_count) = 0; } } return offset; } /*************************************************************************** * Search the TCP header's <options> field for the specified kind/type. * Typical kinds of options are MSS, window scale, SACK, timestamp. ***************************************************************************/ static struct tcp_opt_t tcp_find_opt(const unsigned char *buf, size_t length, unsigned in_kind) { struct tcp_opt_t result = {0}; struct tcp_hdr_t hdr; size_t offset; /* Get the TCP header in the packet */ hdr = _find_tcp_header(buf, length); if (!hdr.is_found) goto fail; /* Search for a matchin <option> */ offset = _find_opt(buf, hdr, in_kind, 0); if (offset >= hdr.max || buf[offset] != in_kind) goto fail; /* We've found it! If we've passed all the checks above, we have * a well formatted field, so just return it. */ result.kind = in_kind; result.buf = buf + offset + 2; result.length = buf[offset+1] - 2; if (offset + result.length >= hdr.max) goto fail; result.is_found = true; return result; fail: result.is_found = false; return result; } /*************************************************************************** * Adjusts the IP "total length" and TCP "header length" fields to match * recent additions/removals of options in the <option-list> ***************************************************************************/ static void _adjust_length(unsigned char *buf, size_t length, int adjustment, struct tcp_hdr_t hdr) { size_t ip_offset = hdr.ip_offset; /* The adjustment should already have been aligned on an even 4 byte * boundary */ if ((adjustment & 0x3) != 0) { fprintf(stderr, "[-] templ.tcp: impossible alignment error\n"); return; } /* Adjust the IP header length */ switch (hdr.ip_version) { case 4: { unsigned total_length; total_length = buf[ip_offset+2] << 8 | buf[ip_offset+3] << 0; total_length += adjustment; buf[ip_offset+2] = (unsigned char)(total_length>>8); buf[ip_offset+3] = (unsigned char)(total_length>>0); total_length = buf[ip_offset+2] << 8 |buf[ip_offset+3] << 0; if (total_length + 14 != length) { fprintf(stderr, "[-] IP length mismatch\n"); } break; } case 6: { unsigned payload_length; payload_length = buf[ip_offset+4] << 8 | buf[ip_offset+5] << 0; payload_length += adjustment; buf[ip_offset+4] = (unsigned char)(payload_length>>8); buf[ip_offset+5] = (unsigned char)(payload_length>>0); break; } } /* Adjust the TCP header length */ { size_t hdr_length; size_t offset = hdr.begin + 12; hdr_length = (buf[offset] >> 4) * 4; hdr_length += adjustment; if (hdr_length % 4 != 0) { fprintf(stderr, "[-] templ.tcp corruptoin\n"); } buf[offset] = (unsigned char)((buf[offset] & 0x0F) | ((hdr_length/4) << 4)); hdr_length = (buf[offset] >> 4) * 4; if (hdr.begin + hdr_length > length) { fprintf(stderr, "[-] templ.tcp corruptoin\n"); } } } /*************************************************************************** * After adding/removing an option, the <option-list> may no longer be * aligned on an even 4-byte boundary as required. This function * adds padding as necessary to align to the boundary. ***************************************************************************/ static void _add_padding(unsigned char **inout_buf, size_t *inout_length, size_t offset, unsigned pad_count) { unsigned char *buf = *inout_buf; size_t length = *inout_length; length += pad_count; buf = realloc(buf, length); /* open space between headers and payload */ safe_memmove(buf, length, offset + pad_count, offset, (length - pad_count) - offset); /* set padding to zero */ safe_memset(buf, length, offset, 0, pad_count); /* Set the out parameters */ *inout_buf = buf; *inout_length = length; } /*************************************************************************** * Afte changes, there my be more padding bytes than necessary. This * reduces the number to 3 or less. Also, it changes any trailing NOPs * to EOL bytes, since there are no more options after that point. ***************************************************************************/ static bool _normalize_padding(unsigned char **inout_buf, size_t *inout_length) { unsigned char *buf = *inout_buf; size_t length = *inout_length; struct tcp_hdr_t hdr; size_t offset; unsigned nop_count = 0; /* find TCP header */ hdr = _find_tcp_header(buf, length); if (!hdr.is_found) goto fail; /* find the start of the padding field */ offset = _find_opt(buf, hdr, 0x100, &nop_count); if (offset >= hdr.max && nop_count == 0) goto success; /* no padding needing to be removed */ /* If NOPs immediately before EOL, include them too */ offset -= nop_count; { size_t remove_count = hdr.max - offset; /* the amount removed must be aligned on 4-byte boundary */ while (remove_count % 4) remove_count--; /* If we have nothing left to remove, then exit. * THIS IS THE NORMAL CASE -- most of the time, we have no * extra padding to remove. */ if (remove_count == 0) goto fail; /* likely, normal*/ //_HEXDUMP(buf, hdr, offset, "before padding removal"); safe_memmove(buf, length, offset, offset + remove_count, length - (offset + remove_count)); hdr.max -= remove_count; length -= remove_count; /* normalize all the bytes to zero, in case they aren't already */ safe_memset(buf, length, offset, 0, hdr.max - offset); //_HEXDUMP(buf, hdr, offset, "after padding removal"); /* fix the IP and TCP length fields */ _adjust_length(buf, length, 0 - (int)remove_count, hdr); } success: *inout_buf = buf; *inout_length = length; return true; /* success */ fail: *inout_buf = buf; *inout_length = length; return false; /* failure */ } /*************************************************************************** ***************************************************************************/ static bool tcp_remove_opt( unsigned char **inout_buf, size_t *inout_length, unsigned in_kind ) { unsigned char *buf = *inout_buf; size_t length = *inout_length; struct tcp_hdr_t hdr; size_t offset; unsigned nop_count = 0; /* find the TCP header */ hdr = _find_tcp_header(buf, length); if (!hdr.is_found) goto fail; /* enumerate all the <options> looking for a match */ offset = _find_opt(buf, hdr, in_kind, &nop_count); if (offset + 2 >= hdr.max) goto success; /* not found, no matching option type/kind */ { unsigned opt_len = buf[offset+1]; unsigned remove_length = opt_len; if (offset + opt_len > hdr.max) goto fail; /* Remove any trailing NOPs */ while (offset + remove_length < hdr.max && buf[offset + remove_length] == 1) remove_length++; /* Remove any leading NOPs */ offset -= nop_count; remove_length += nop_count; /* Remove the bytes from the current packet buffer. * Before this will be the ...IP/TCP headers plus maybe some options. * After this will be maybe some options, padding, then the TCP payload * */ //_HEXDUMP(buf, hdr, offset, "before removal"); safe_memmove(buf, length, offset, offset + remove_length, length - (offset + remove_length)); hdr.max -= remove_length; length -= remove_length; //_HEXDUMP(buf, hdr, offset, "after removal"); /* Now we may need to add back padding */ if (remove_length % 4) { unsigned add_length = (remove_length % 4); _add_padding(&buf, &length, hdr.max, add_length); remove_length -= add_length; hdr.max += add_length; } //_HEXDUMP(buf, hdr, offset, "padding added"); /* fix the IP and TCP length fields */ _adjust_length(buf, length, 0 - remove_length, hdr); /* In case we've padded the packet with four 0x00, get rid * of them */ _normalize_padding(&buf, &length); } success: *inout_buf = buf; *inout_length = length; return true; fail: *inout_buf = buf; *inout_length = length; return false; } /*************************************************************************** ***************************************************************************/ static int _insert_field(unsigned char **inout_buf, size_t *inout_length, size_t offset_begin, size_t offset_end, const unsigned char *new_data, size_t new_length ) { unsigned char *buf = *inout_buf; size_t length = *inout_length; int adjust = 0; /* can theoreitcally be negative, but that's ok */ adjust = (int)new_length - ((int)offset_end - (int)offset_begin); if (adjust > 0) { length += adjust; buf = realloc(buf, length); safe_memmove(buf, length, offset_begin + new_length, offset_end, (length - adjust) - offset_end); } if (adjust < 0) { safe_memmove(buf, length, offset_begin + new_length, offset_end, length - offset_end); length += adjust; buf = realloc(buf, length); } /**/ memcpy(buf + offset_begin, new_data, new_length); *inout_buf = buf; *inout_length = length; return adjust; } /** Calculate the total number of padding bytes, both NOPs in the middle * and EOLs at the end. We call this when there's not enough space for * another option, and we want to remove all the padding. */ #if 0 static unsigned _calc_padding(const unsigned char *buf, struct tcp_hdr_t hdr) { size_t offset; unsigned result = 0; /* enumerate through all <option> fields */ for (offset = _opt_begin(hdr); offset < hdr.max; offset = _opt_next(hdr, offset, buf)) { unsigned kind; /* Get the kind: 0=EOL, 1=NOP, 2=MSS, 3=Wscale, etc. */ kind = buf[offset]; /* If EOL, we end here, and all the remainder bytes are counted * as padding. */ if (kind == 0) { result += (hdr.max - offset); break; } /* If a NOP, then this is a padding byte */ if (kind == 1) result++; } return result; } #endif /*************************************************************************** * Remove all the padding bytes, and return an offset to the beginning * of the rest of the option field. ***************************************************************************/ static size_t _squeeze_padding(unsigned char *buf, size_t length, struct tcp_hdr_t hdr, unsigned in_kind) { size_t offset; unsigned nop_count = 0; for (offset = _opt_begin(hdr); offset < hdr.max; offset = _opt_next(hdr, offset, buf)) { unsigned kind; unsigned len; //_HEXDUMP(buf, hdr, offset, "squeeze"); /* Get the kind: 0=EOL, 1=NOP, 2=MSS, 3=Wscale, etc. */ kind = buf[offset]; /* If a NOP padding, simply count it until we reach something * more interesting */ if (kind == 0x01) { nop_count++; continue; } /* If end of option list, any remaining padding bytes are added */ if (kind == 0x00) { /* normalize the padding at the end */ offset -= nop_count; safe_memset(buf, length, offset, 0, hdr.max - offset); //_HEXDUMP(buf, hdr, offset, "null"); return offset; } /* If we match an existing field, all those bytes become padding */ if (kind == in_kind) { len = buf[offset+1]; safe_memset(buf, length, offset, 0x01, len); nop_count++; //_HEXDUMP(buf, hdr, offset, "VVVVV"); continue; } if (nop_count == 0) continue; /*no squeezing needed */ /* move this field backward overwriting NOPs */ len = buf[offset+1]; safe_memmove(buf, length, offset - nop_count, offset, len); //_HEXDUMP(buf, hdr, offset - nop_count, "<<<<"); /* now write NOPs where this field used to be */ safe_memset(buf, length, offset + len - nop_count, 0x01, nop_count); //_HEXDUMP(buf, hdr, offset + len - nop_count, "!!!!!"); /* reset the <offset> to the end of this relocated field */ offset -= nop_count; nop_count = 0; } /* if we reach the end, then there were only NOPs at the end and no * EOL byte, so simply zero them out */ safe_memset(buf, length, offset - nop_count, 0x00, nop_count); offset -= nop_count; //_HEXDUMP(buf, hdr, offset, ""); return offset; } /*************************************************************************** ***************************************************************************/ static bool tcp_add_opt(unsigned char **inout_buf, size_t *inout_length, unsigned opt_kind, unsigned opt_length, const unsigned char *opt_data) { unsigned char *buf = *inout_buf; size_t length = *inout_length; struct tcp_hdr_t hdr; size_t offset; unsigned nop_count = 0; int adjust = 0; /* Check for corruption: * The maximum size of a TCP header is 60 bytes (0x0F * 4), and the * rest of the header takes up 20 bytes. The [kind,length] takes up * another 2 bytes. Thus, the max option length is 38 bytes */ if (opt_length > 38) { fprintf(stderr, "[-] templ.tcp.add_opt: opt_len too large\n"); goto fail; } /* find TCP header */ hdr = _find_tcp_header(buf, length); if (!hdr.is_found) goto fail; /* enumerate all existing options looking match */ offset = _find_opt(buf, hdr, opt_kind, &nop_count); { size_t old_begin; size_t old_end; unsigned char new_field[64]; size_t new_length; /* Create a well-formatted field that will be inserted */ new_length = 1 + 1 + opt_length; new_field[0] = (unsigned char)opt_kind; new_field[1] = (unsigned char)new_length; memcpy(new_field + 2, opt_data, opt_length); /* Calculate the begin/end of the existing field in the packet */ old_begin = offset; if (old_begin >= hdr.max) old_end = hdr.max; /* will insert end of header */ else if (buf[offset] == 0x00) old_end = hdr.max; /* will insert start of padding */ else if (buf[offset] == opt_kind) { /* will replace old field */ size_t len = buf[offset + 1]; old_end = offset + len; } else { fprintf(stderr, "[-] not possible i09670t\n"); return false; } /* If the existing space is too small, try to expand it by * using neighboring (leading, trailing) NOPs */ while ((old_end-old_begin) < new_length) { if (nop_count) { nop_count--; old_begin--; } else if (old_end < hdr.max && buf[old_end] == 0x01) { old_end++; } else break; } /* If the existing space is too small, and we are at the end, * and there's pading, then try to use the padding */ if ((old_end-old_begin) < new_length) { if (old_end < hdr.max) { if (buf[old_end] == 0x00) { /* normalize padding to all zeroes */ safe_memset(buf, length, old_end, 0, hdr.max - old_end); while ((old_end-old_begin) < new_length) { if (old_end >= hdr.max) break; old_end++; } } } } /* Make sure we have enough space in the header */ { static const size_t max_tcp_hdr = (0xF0>>4) * 4; /* 60 */ size_t added = new_length - (old_end - old_begin); if (hdr.max + added > hdr.begin + max_tcp_hdr) { //unsigned total_padding = _calc_padding(buf, hdr); old_begin = _squeeze_padding(buf, length, hdr, opt_kind); old_end = hdr.max; } } /* Now insert the option field into packet. This may change the * sizeof the packet. The amount changed is indicated by 'adjust' */ adjust = _insert_field(&buf, &length, old_begin, old_end, new_field, new_length); hdr.max += adjust; } if (adjust) { /* TCP headers have to be aligned to 4 byte boundaries, so we may need * to add padding of 0 at the end of the header to handle this */ if (adjust % 4 && adjust > 0) { unsigned add_length = 4 - (adjust % 4); _add_padding(&buf, &length, hdr.max, add_length); hdr.max += add_length; adjust += add_length; } else if (adjust % 4 && adjust < 0) { unsigned add_length = 0 - (adjust % 4); //_HEXDUMP(buf, hdr, hdr.max, "pad before"); _add_padding(&buf, &length, hdr.max, add_length); hdr.max += add_length; adjust += add_length; //_HEXDUMP(buf, hdr, hdr.max, "pad after"); } /* fix the IP and TCP length fields */ _adjust_length(buf, length, adjust, hdr); /* In case we've padded the packet with four 0x00, get rid * of them */ _normalize_padding(&buf, &length); } *inout_buf = buf; *inout_length = length; return true; fail: /* no changes were made */ *inout_buf = buf; *inout_length = length; return false; } /*************************************************************************** ***************************************************************************/ static unsigned tcp_get_mss(const unsigned char *buf, size_t length, bool *is_found) { struct tcp_opt_t opt; unsigned result = 0; opt = tcp_find_opt(buf, length, 2 /* MSS */); if (is_found) *is_found = opt.is_found; if (!opt.is_found) return 0xFFFFffff; if (opt.length != 2) { /* corrupt */ if (is_found) *is_found = false; return 0xFFFFffff; } result = opt.buf[0] << 8 | opt.buf[1]; return result; } /*************************************************************************** ***************************************************************************/ static unsigned tcp_get_wscale(const unsigned char *buf, size_t length, bool *is_found) { struct tcp_opt_t opt; unsigned result = 0; opt = tcp_find_opt(buf, length, 3 /* Wscale */); if (is_found) *is_found = opt.is_found; if (!opt.is_found) return 0xFFFFffff; if (opt.length != 1) { /* corrupt */ if (is_found) *is_found = false; return 0xFFFFffff; } result = opt.buf[0]; return result; } /*************************************************************************** ***************************************************************************/ static unsigned tcp_get_sackperm(const unsigned char *buf, size_t length, bool *is_found) { struct tcp_opt_t opt; opt = tcp_find_opt(buf, length, 3 /* Wscale */); if (is_found) *is_found = opt.is_found; if (!opt.is_found) return 0xFFFFffff; if (opt.length != 1) { /* corrupt */ if (is_found) *is_found = false; return 0xFFFFffff; } return 0; } /*************************************************************************** * Called at the end of configuration, to change the TCP header template * according to configuration. For example, we might add a "sackperm" field, * or delete an "mss" field, or change the value of "mss". ***************************************************************************/ void templ_tcp_apply_options(unsigned char **inout_buf, size_t *inout_length, const struct TemplateOptions *templ_opts) { unsigned char *buf = *inout_buf; size_t length = *inout_length; if (templ_opts == NULL) return; /* --tcp-mss <num> * Sets maximum segment size */ if (templ_opts->tcp.is_mss == Remove) { tcp_remove_opt(&buf, &length, 2 /* mss */); } else if (templ_opts->tcp.is_mss == Add) { unsigned char field[2]; field[0] = (unsigned char)(templ_opts->tcp.mss>>8); field[1] = (unsigned char)(templ_opts->tcp.mss>>0); tcp_add_opt(&buf, &length, 2, 2, field); } /* --tcp-sackok * Sets option flag that permits selective acknowledgements */ if (templ_opts->tcp.is_sackok == Remove) { tcp_remove_opt(&buf, &length, 4 /* sackok */); } else if (templ_opts->tcp.is_sackok == Add) { tcp_add_opt(&buf, &length, 4, 0, (const unsigned char*)""); } /* --tcp-wscale <num> * Sets window scale option */ if (templ_opts->tcp.is_wscale == Remove) { tcp_remove_opt(&buf, &length, 3 /* wscale */); } else if (templ_opts->tcp.is_wscale == Add) { unsigned char field[1]; field[0] = (unsigned char)templ_opts->tcp.wscale; tcp_add_opt(&buf, &length, 3, 1, field); } /* --tcp-ts <num> * Timestamp */ if (templ_opts->tcp.is_tsecho == Remove) { tcp_remove_opt(&buf, &length, 8 /* ts */); } else if (templ_opts->tcp.is_tsecho == Add) { unsigned char field[10] = {0}; field[0] = (unsigned char)(templ_opts->tcp.tsecho>>24); field[1] = (unsigned char)(templ_opts->tcp.tsecho>>16); field[2] = (unsigned char)(templ_opts->tcp.tsecho>>8); field[2] = (unsigned char)(templ_opts->tcp.tsecho>>0); tcp_add_opt(&buf, &length, 8, 8, field); } *inout_buf = buf; *inout_length = length; } /*************************************************************************** * Used during selftests in order to create a known options field as the * starting before before changing it somehow, followed by using * _compare_options() to test whether the change succeeded. ***************************************************************************/ static bool _replace_options(unsigned char **inout_buf, size_t *inout_length, const char *new_options, size_t new_length) { unsigned char *buf = *inout_buf; size_t length = *inout_length; struct tcp_hdr_t hdr; size_t offset; size_t old_length; char newnew_options[40] = {0}; int adjust = 0; /* Maximum length of the options field is 40 bytes */ if (new_length > 40) goto fail; /* Pad new options to 4 byte boundary */ memcpy(newnew_options, new_options, new_length); while (new_length % 4) new_length++; /* find TCP header */ hdr = _find_tcp_header(buf, length); if (!hdr.is_found) goto fail; /* Find start of options field */ offset = _opt_begin(hdr); old_length = hdr.max - offset; /* Either increase or decrease the old length appropriately */ //_HEXDUMPopt(buf, length, "resize before"); adjust = (int)(new_length - old_length); if (adjust > 0) { length += adjust; buf = realloc(buf, length); safe_memmove(buf, length, hdr.max + adjust, hdr.max, (length - adjust) - hdr.max); } if (adjust < 0) { safe_memmove( buf, length, hdr.max + adjust, hdr.max, length - hdr.max); length += adjust; buf = realloc(buf, length); } /* Now that we've resized the options field, overright * it with then new field */ memcpy(buf + offset, newnew_options, new_length); /* fix the IP and TCP length fields */ _adjust_length(buf, length, adjust, hdr); //_HEXDUMPopt(buf, length, "resize after"); *inout_buf = buf; *inout_length = length; return true; fail: *inout_buf = buf; *inout_length = length; return false; } /*************************************************************************** ***************************************************************************/ enum { TST_NONE, TST_PADDING, TST_ADD, TST_REMOVE, }; /*************************************************************************** * This structure specifies test cases for the sefltest function. Each * test has a pre-condition <options-list>, and option to add/remove, and * a post-condition <options-list> that should match the result. ***************************************************************************/ struct mytests_t { struct { const char *options; size_t length; } pre; struct { int opcode; const char *data; size_t length; } test; struct { const char *options; size_t length; } post; }; /*************************************************************************** * The following tests add/remove options to a test packet. The goal of * these tests is code-coverage of all the conditions above, testing * all the boundary cases. Every code path that produces success is tested, * plus many code paths that produce failures. ***************************************************************************/ static struct mytests_t tests[] = { /* A lot of these tests use 2-byte (\4\2) and 3-byte (\3\3\3) options. * The "\4\2" is "SACK permitted, kind=4, len=2, with no extra data. * The "\3\3\3" is "Window Scale, kind=3, len=3, data=3. * The "\2\4\5\6" is "Max Segment Size", kind=2, len=4, data=0x0506 */ /* Attempt removal of an option that doesn't exist. This is not * a failure, but a success, though nothing is changed*/ { {"\3\3\3\0", 4}, {TST_REMOVE, "\x08", 1}, {"\3\3\3\0", 4} }, /* Test removal of an option. This will also involve removing the now unnecessary padding */ { {"\3\3\3\1\1\1\x08\x0a\x1d\xe9\xb2\x98\x00\x00\x00\x00", 16}, {TST_REMOVE, "\x08", 1}, {"\3\3\3\0", 4} }, /* Test when trying to add a big option that won't fit unless we get * rid of all the padding */ { { "\x02\x04\x05\xb4" "\x01\x03\x03\x06" "\x01\x01\x08\x0a\x1d\xe9\xb2\x98\x00\x00\x00\x00" "\x04\x02\x00\x00" "\0\0\0\0", 28}, { TST_ADD, "\7\x14" "AAAAAAAAAAAAAAAAAAAA", 20 }, { "\x02\x04\x05\xb4" "\x03\x03\x06" "\x08\x0a\x1d\xe9\xb2\x98\x00\x00\x00\x00" "\x04\x02" "\7\x14" "AAAAAAAAAAAAAAAAAA" "\0", 40 } }, /* same as a bove, but field exists*/ {{ "\x02\x04\x05\xb4" "\x01\x03\x03\x06" "\x01\x01\x08\x0a\x1d\xe9\xb2\x98\x00\x00\x00\x00" "\7\4\1\1" "\x04\x02\x00\x00", 28}, { TST_ADD, "\7\x14" "AAAAAAAAAAAAAAAAAAAA", 20 }, { "\x02\x04\x05\xb4" "\x03\x03\x06" "\x08\x0a\x1d\xe9\xb2\x98\x00\x00\x00\x00" "\x04\x02" "\7\x14" "AAAAAAAAAAAAAAAAAA" "\0", 40 } }, /* Add a new value to full packet */ {{"\3\3\3", 3}, {TST_ADD, "\4\2", 2}, {"\3\3\3\4\2\0\0\0", 8}}, /* Change a 3 byte to 5 byte in middle of packet */ {{"\1\7\3\3\1\1\4\2", 8}, {TST_ADD, "\7\5\5\5\5", 5}, {"\7\5\5\5\5\1\4\2", 8}}, /* Change 3 to 4 byte at start */ {{"\7\3\3\1\2\4\5\6", 8}, {TST_ADD, "\7\4\4\4", 4}, {"\7\4\4\4\2\4\5\6", 8}}, /* Change a 2-byte option */ {{"\4\2", 2}, {TST_ADD, "\4\2", 2}, {"\4\2\0\0", 4}}, /* Change a 3-byte option */ {{"\3\3\2", 3}, {TST_ADD, "\3\3\3", 3}, {"\3\3\3\0", 4}}, /* Change a 4-byte option */ {{"\2\4\1\1", 4}, {TST_ADD, "\2\4\5\6", 4}, {"\2\4\5\6", 4}}, /* Add a 2-byte option to empty packet*/ {{"", 0}, {TST_ADD, "\4\2", 2}, {"\4\2\0\0", 4}}, /* Add a 3-byte option to empty packet*/ {{"", 0}, {TST_ADD, "\3\3\3", 3}, {"\3\3\3\0", 4}}, /* Add a 4-byte option to empty packet*/ {{"", 0}, {TST_ADD, "\2\4\5\6", 4}, {"\2\4\5\6", 4}}, /* Empty packet: padding normalization should make no changes */ {{"", 0}, {TST_PADDING,0,0}, {"", 0}}, /* Empty packet plus 4 bytes of padding, should be removed */ {{"\0", 1}, {TST_PADDING,0,0}, {"", 0}}, /* 8 bytes of padding, should only remove all of them */ {{"\0\0\0\0\0\0\0\0", 8}, {TST_PADDING,0,0}, {"", 0}}, /* some padding is nops, should remove all */ {{"\1\1\0\0\0\0\0\0", 8}, {TST_PADDING,0,0}, {"", 0}}, /* any trailing NOPs should be converted to EOLs */ {{"\3\3\3\1\0\0\0\0", 8}, {TST_PADDING,0,0}, {"\3\3\3\0", 4}}, /* only NOPs should still be removed */ {{"\3\3\3\1\1\1\1\1", 8}, {TST_PADDING,0,0}, {"\3\3\3\0", 4}}, {{0}} }; /*************************************************************************** * This function runs through the tests in the [tests] array above. It * first creates a packet accoding to a pre-condition that may have * options already. We then call a function to manipulate the packet, * such as adding/changing an option. We then verify that that the * <option-list> field now matches the post-condition. Along the way, * we look for any errors are consistency failures. ***************************************************************************/ static int _selftests_run(void) { static unsigned char templ[] = "\0\1\2\3\4\5" /* Ethernet: destination */ "\6\7\x8\x9\xa\xb" /* Ethernet: source */ "\x08\x00" /* Ethernet type: IPv4 */ "\x45" /* IP type */ "\x00" "\x00\x48" /* total length = 64 bytes */ "\x00\x00" /* identification */ "\x00\x00" /* fragmentation flags */ "\xFF\x06" /* TTL=255, proto=TCP */ "\xFF\xFF" /* checksum */ "\0\0\0\0" /* source address */ "\0\0\0\0" /* destination address */ "\0\0" /* source port */ "\0\0" /* destination port */ "\0\0\0\0" /* sequence number */ "\0\0\0\0" /* ACK number */ "\xB0" /* header length */ "\x02" /* SYN */ "\x04\x01" /* window fixed to 1024 */ "\xFF\xFF" /* checksum */ "\x00\x00" /* urgent pointer */ "\x02\x04\x05\xb4" "\x01\x03\x03\x06" "\x01\x01\x08\x0a\x1d\xe9\xb2\x98\x00\x00\x00\x00" "\x04\x02\x00\x00" "DeadBeef" ; size_t i; /* execute all tests */ for (i=0; tests[i].pre.options; i++) { unsigned char *buf; size_t length = sizeof(templ) - 1; bool success; struct tcp_hdr_t hdr; const unsigned char *field; size_t field_length; LOG(1, "[+] templ-tcp-hdr: run #%u\n", (unsigned)i); /* Each tests creates its own copy of the test packet, which it * will then alter according to the pre-conditions. */ buf = malloc(length); memcpy(buf, templ, length); /* Set the pre-condition <option-list> field by replacing what * was there with a completely new field */ success = _replace_options(&buf, &length, tests[i].pre.options, tests[i].pre.length); if (!success) goto fail; /* this should never happen */ if (_consistancy_check(buf, length, "DeadBeef", 8)) goto fail; /* this shoiuld never happen*/ //_HEXDUMPopt(buf, length, "[PRE]"); /* * Run the desired test */ switch (tests[i].test.opcode) { case TST_PADDING: /* We are testing the "normalize padding" function. This * is called after ever 'add' or 'remove' to make sure that * the padding at the end is consistent. Mostly, it means * that when we remove a field, we'll probably have excess * padding at the end, which needs to be trimmed to the * minimum amount of padding */ success = _normalize_padding(&buf, &length); if (!success) goto fail; break; case TST_ADD: /* We are testing `tcp_add_opt()` function, which is called * to either 'add' or 'change' an existing option. */ field = (const unsigned char*)tests[i].test.data; field_length = tests[i].test.length; if (field_length < 2) goto fail; else { unsigned opt_kind = field[0]; unsigned opt_length = field[1]; const unsigned char *opt_data = field + 2; if (field_length != opt_length) goto fail; /* skip the KIND and LENGTH fields, justa DATA length */ opt_length -= 2; success = tcp_add_opt(&buf, &length, opt_kind, opt_length, opt_data); if (!success) goto fail; } break; case TST_REMOVE: /* We are testing `tcp_add_opt()` function, which is called * to either 'add' or 'change' an existing option. */ field = (const unsigned char*)tests[i].test.data; field_length = tests[i].test.length; if (field_length != 1) goto fail; else { unsigned opt_kind = field[0]; success = tcp_remove_opt(&buf, &length, opt_kind); if (!success) goto fail; } break; default: return 1; /* fail */ } //_HEXDUMPopt(buf, length, "[POST]"); if (_consistancy_check(buf, length, "DeadBeef", 8)) goto fail; /* * Make sure output matches expected results */ { size_t offset; int err; size_t post_length; /* Find the <options-list> field */ hdr = _find_tcp_header(buf, length); if (!hdr.is_found) goto fail; offset = _opt_begin(hdr); /* Make sure the length matches the expected length */ post_length = hdr.max - offset; if (tests[i].post.length != post_length) goto fail; /* makre sure the contents of the field match expected */ err = memcmp(tests[i].post.options, buf+offset, (hdr.max-offset)); if (err) { _HEXDUMPopt(buf, length, "[-] failed expectations"); goto fail; } } free(buf); } return 0; /* success */ fail: fprintf(stderr, "[-] templ.tcp.selftest failed, test #%u\n", (unsigned)i); return 1; }; /*************************************************************************** * These self-tests manipulate a TCP header, adding and removing <option> * fields in various scenarios. We expose the `tcp_add_option()` function * to the end-user via the command-line, so we have to anticipate that * the option they want added is going to be corrupt. For example, the * end-user might try to add an option that overflows the <option-list> * field, which is rather small (only 40 bytes long). ***************************************************************************/ int templ_tcp_selftest(void) { static unsigned char templ[] = "\0\1\2\3\4\5" /* Ethernet: destination */ "\6\7\x8\x9\xa\xb" /* Ethernet: source */ "\x08\x00" /* Ethernet type: IPv4 */ "\x45" /* IP type */ "\x00" "\x00\x48" /* total length = 64 bytes */ "\x00\x00" /* identification */ "\x00\x00" /* fragmentation flags */ "\xFF\x06" /* TTL=255, proto=TCP */ "\xFF\xFF" /* checksum */ "\0\0\0\0" /* source address */ "\0\0\0\0" /* destination address */ "\0\0" /* source port */ "\0\0" /* destination port */ "\0\0\0\0" /* sequence number */ "\0\0\0\0" /* ACK number */ "\xB0" /* header length */ "\x02" /* SYN */ "\x04\x01" /* window fixed to 1024 */ "\xFF\xFF" /* checksum */ "\x00\x00" /* urgent pointer */ "\x02\x04\x05\xb4" "\x01\x03\x03\x06" "\x01\x01\x08\x0a\x1d\xe9\xb2\x98\x00\x00\x00\x00" "\x04\x02\x00\x00" "DeadBeef" ; size_t length = sizeof(templ) - 1; unsigned char *buf; /* Execute planned selftests */ if (_selftests_run()) return 1; /* We need to make an allocated copy of the buffer, because the * size may change from `realloc()` */ buf = malloc(length); memcpy(buf, templ, length); /* * Make sure we start wtih an un-corrupted test packet */ if (_consistancy_check(buf, length, "DeadBeef", 8)) goto fail; if (1460 != tcp_get_mss(buf, length, 0)) goto fail; if (6 != tcp_get_wscale(buf, length, 0)) goto fail; if (0 != tcp_get_sackperm(buf, length, 0)) goto fail; tcp_add_opt(&buf, &length, 2, 2, (const unsigned char*)"\x12\x34"); if (0x1234 != tcp_get_mss(buf, length, 0)) goto fail; if (_consistancy_check(buf, length, "DeadBeef", 8)) goto fail; tcp_remove_opt(&buf, &length, 3); if (0x1234 != tcp_get_mss(buf, length, 0)) goto fail; if (0xFFFFffff != tcp_get_wscale(buf, length, 0)) goto fail; if (_consistancy_check(buf, length, "DeadBeef", 8)) goto fail; free(buf); return 0; /* success */ fail: free(buf); return 1; /* failure */ }
52,588
C
.c
1,353
30.920916
98
0.491015
robertdavidgraham/masscan
23,250
3,042
399
AGPL-3.0
9/7/2024, 9:40:14 AM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
5,411
templ-payloads.c
robertdavidgraham_masscan/src/templ-payloads.c
/* Reads in UDP payload templates. This supports two formats. The first format is the "nmap-payloads" file included with the nmap port scanner. The second is the "libpcap" format that reads in real packets, extracting just the payloads, associated them with the destination UDP port. */ #include "templ-payloads.h" #include "massip-port.h" #include "rawsock-pcapfile.h" /* for reading payloads from pcap files */ #include "proto-preprocess.h" /* parse packets */ #include "util-logger.h" #include "proto-zeroaccess.h" /* botnet p2p protocol */ #include "proto-snmp.h" #include "proto-memcached.h" #include "proto-coap.h" /* constrained app proto for IoT udp/5683*/ #include "proto-ntp.h" #include "proto-dns.h" #include "proto-isakmp.h" #include "util-malloc.h" #include "massip.h" #include "templ-nmap-payloads.h" #include <stdio.h> #include <string.h> #include <ctype.h> #include <stdlib.h> struct PayloadUDP_Item { unsigned port; unsigned source_port; /* not used yet */ unsigned length; unsigned xsum; unsigned rarity; SET_COOKIE set_cookie; unsigned char buf[1]; }; struct PayloadUDP_Default { unsigned port; unsigned source_port; unsigned length; unsigned xsum; SET_COOKIE set_cookie; char *buf; }; struct PayloadsUDP { unsigned count; size_t max; struct PayloadUDP_Item **list; }; struct PayloadUDP_Default hard_coded_oproto_payloads[] = { /* ECHO protocol - echoes back whatever we send */ {47, 65536, 4, 0, 0, "\0\0\0\0"}, {0,0,0,0,0} }; struct PayloadUDP_Default hard_coded_udp_payloads[] = { /* ECHO protocol - echoes back whatever we send */ {7, 65536, 12, 0, 0, "masscan-test 0x00000000"}, /* QOTD - quote of the day (amplifier) */ {17, 65536, 12, 0, 0, "masscan-test"}, /* chargen - character generator (amplifier) */ {19, 65536, 12, 0, 0, "masscan-test"}, {53, 65536, 0x1f, 0, dns_set_cookie, /* 00 */"\x50\xb6" /* transaction id */ /* 02 */"\x01\x20" /* query */ /* 04 */"\x00\x01" /* query = 1 */ /* 06 */"\x00\x00\x00\x00\x00\x00" /* 0c */"\x07" "version" "\x04" "bind" "\x00" /* 1b */"\x00\x10" /* TXT */ /* 1d */"\x00\x03" /* CHAOS */ /* 1f */ }, {69, 65536, 24, 0, 0, "\x00\x01" /* opcode = read */ "masscan-test" "\0" /* filename = "masscan-test" */ "netascii" "\0" /* type = "netascii" */ }, /* portmapper */ {111, 65536, 40, 0, dns_set_cookie, "\x00\x00\x00\x00" /* xid - first two bytes set by dns_set_cookie() */ "\x00\x00\x00\x00" /* RPC opcode = CALL*/ "\x00\x00\x00\x02" /* RPC version = 2 */ "\x00\x01\x86\xa0" /* RPC program = NFS */ "\x00\x00\x00\x02" /* portmapper version = 2 */ "\x00\x00\x00\x00" /* portmapper procedure = 0 (NULL, ping) */ "\x00\x00\x00\x00\x00\x00\x00\x00" /* credentials = none*/ "\x00\x00\x00\x00\x00\x00\x00\x00" /* verifier = none */ }, {123, 65536, 48, 0, ntp_set_cookie, "\x17\x00\x03\x2a\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" }, {137, 65536, 50, 0, dns_set_cookie, "\xab\x12" /* transaction id */ "\x00\x00" /* query */ "\x00\x01\x00\x00\x00\x00\x00\x00" /* one question */ "\x20" /*name length*/ "CKAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA" "\x00" "\x00\x21" /* type = nbt */ "\x00\x01" /* class = iternet*/ }, /* NetBIOS-SMB BROWSER protocol */ {138, 65536, 174, 0, 0, "\x11" /* broadcast datagram */ "\x0a" /* flags */ "\xc1\x00" /* datagram id */ "\x0a\x01\x01\xd5" /* source IP */ "\x00\x8a" /* source port */ "\x00\xa0" /* length */ "\x00\x00" /* packet offset */ "\x20" /* namelength = 32 bytes*/ "ENEBFDFDEDEBEOCNFEEFFDFECACACAAA" /* "MASSCAN-TEST<00>" */ "\x00" "\x20" "FHEPFCELEHFCEPFFFACACACACACACABN" /* "WORKGROUP<1D>*/ "\x00" "\xff\x53\x4d\x42\x25\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" "\x11\x00\x00\x06\x00\x00\x00\x00\x00\x00\x00\x00\x00\xe8\x03\x00" "\x00\x00\x00\x00\x00\x00\x00\x06\x00\x56\x00\x03\x00\x01\x00\x01" "\x00\x02\x00\x17\x00\x5c\x4d\x41\x49\x4c\x53\x4c\x4f\x54\x5c\x42" "\x52\x4f\x57\x53\x45\x00" "\x09\x04\x01\x00\x00\x00" }, {161, 65536, 59, 0, snmp_set_cookie, "\x30" "\x39" "\x02\x01\x00" /* version */ "\x04\x06" "public" /* community = public */ "\xa0" "\x2c" /* type = GET */ "\x02\x04\x00\x00\x00\x00" /* transaction id = ???? */ "\x02\x01\x00" /* error = 0 */ "\x02\x01\x00" /* error index = 0 */ "\x30\x1e" "\x30\x0d" "\x06\x09\x2b\x06\x01\x80\x02\x01\x01\x01\x00" /*sysName*/ "\x05\x00" /*^^^^_____IDS LULZ HAH HA HAH*/ "\x30\x0d" "\x06\x09\x2b\x06\x01\x80\x02\x01\x01\x05\x00" /*sysDesc*/ "\x05\x00"}, /*^^^^_____IDS LULZ HAH HA HAH*/ {443, 65536, 115, 0, 0, "\x16" /* opcode = handshake */ "\xfe\xff" /* version = dTLS v1.0 */ "\x00\x00" /* epoch = 0 */ "\x00\x00\x00\x00\x00\x07" /* sequence number = 7 */ "\x00\x66" /* length 104 */ "\x01" /* opcode = client hello */ "\x00\x00\x5a" /* length 90 */ "\x00\x00" /* sequence number = 0 */ "\x00\x00\x00" /* fragment offset = 0 */ "\x00\x00\x5a" /* framgent length = 90 */ "\xfe\xfd" /* version = dTLS v1.2 */ "\x1d\xb1\xe3\x52\x2e\x89\x94\xb7\x15\x33\x2f\x30\xff\xff\xcf\x76" "\x27\x77\xab\x04\xe4\x86\x6f\x21\x18\x0e\xf8\xdd\x70\xcc\xab\x9e" "\x00" /* session id length = 0 */ "\x00" /* cookie length = 0 */ "\x00\x04" /* cipher suites length = 4 */ "\xc0\x30" /* TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 */ "\x00\xff" "\x01" /* compression methods length = 1*/ "\x00" /* NULL compression */ "\x00\x2c" /* extensions length = 44 */ "\x00\x0b\x00\x04\x03\x00\x01\x02" "\x00\x0a\x00\x0c\x00\x0a\x00\x1d\x00\x17\x00\x1e\x00\x19\x00\x18" "\x00\x23\x00\x00" "\x00\x16\x00\x00" "\x00\x17\x00\x00" "\x00\x0d\x00\x04\x00\x02\x05\x01" }, {520, 65536, 24, 0, 0, "\x01" /* opcode = request */ "\x01" /* version = 1 */ "\x00\x00" /* padding */ "\x00\x02" /* address familly = IPv4 */ "\x00\x00" "\x00\x00\x00\x00" "\x00\x00\x00\x00" "\x00\x00\x00\x00" "\x00\x00\x00\x10" /* metric = 16 */ }, /* RADIUS */ {1645, 65536, 20, 0, 0, "\x01" /* opcode = access request */ "\x00" /* packet id = 0 */ "\x00\x14" /* length = 20 */ "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" }, {1812, 65536, 20, 0, 0, "\x01" /* opcode = access request */ "\x00" /* packet id = 0 */ "\x00\x14" /* length = 20 */ "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" }, {1646, 65536, 20, 0, 0, "\x04" /* opcode = access request */ "\x00" /* packet id = 0 */ "\x00\x14" /* length = 20 */ "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" }, {1813, 65536, 20, 0, 0, "\x04" /* opcode = access request */ "\x00" /* packet id = 0 */ "\x00\x14" /* length = 20 */ "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" }, /* L2TP */ {1701, 65536, 60, 0, 0, "\xc8\x02" /* flags */ "\x00\x3c" /* length = 60 */ "\x00\x00" /* tunnel id = 0 */ "\x00\x00" /* session id = 0 */ "\x00\x00" /* Nsent = 0 */ "\x00\x00" /* Nrecvd = 0 */ "\x80\x08\x00\x00\x00\x00\x00\x01" /* control message */ "\x80\x08\x00\x00\x00\x02\x01\x00" /* protocol version */ "\x80\x0e\x00\x00\x00\x07" "masscan1" /* hostname */ "\x80\x0a\x00\x00\x00\x03\x00\x00\x00\x03" /* framing capabilities */ "\x80\x08\x00\x00\x00\x09\x00\x00" /* assigned tunnel */ }, /* UPnP SSDP - Univeral Plug-n-Play Simple Service Discovery Protocol */ {1900, 65536, 0xFFFFFFFF, 0, 0, "M-SEARCH * HTTP/1.1\r\n" "HOST: 239.255.255.250:1900\r\n" "MAN: \"ssdp:discover\"\r\n" "MX: 1\r\n" "ST: ssdp:all\r\n" "USER-AGENT: unix/1.0 UPnP/1.1 masscan/1.x\r\n"}, /* NFS - kludge: use the DNS cookie, setting first 2 bytes instead of 4 */ {2049, 65536, 40, 0, dns_set_cookie, "\x00\x00\x00\x00" /* xid - first two bytes set by dns_set_cookie() */ "\x00\x00\x00\x00" /* RPC opcode = CALL*/ "\x00\x00\x00\x02" /* RPC version = 2 */ "\x00\x01\x86\xa3" /* RPC program = NFS */ "\x00\x00\x00\x02" /* NFS version = 2 */ "\x00\x00\x00\x00" /* NFS procedure = 0 (NULL, ping) */ "\x00\x00\x00\x00\x00\x00\x00\x00" /* credentials = none*/ "\x00\x00\x00\x00\x00\x00\x00\x00" /* verifier = none */ }, {5060, 65536, 0xFFFFFFFF, 0, 0, "OPTIONS sip:[email protected] SIP/2.0\r\n" "Via: SIP/2.0/UDP pc33.atlanta.com;branch=z9hG4bKhjhs8ass877\r\n" "Max-Forwards: 70\r\n" "To: <sip:[email protected]>\r\n" "From: Alice <sip:[email protected]>;tag=1928301774\r\n" "Call-ID: a84b4c76e66710\r\n" "CSeq: 63104 OPTIONS\r\n" "Contact: <sip:[email protected]>\r\n" "Accept: application/sdp\r\n" "Content-Length: 0\r\n" }, /* CoAP (contrained app proto for IoT) GET /.well-known/core request */ {5683, 65536, 21, 0, coap_udp_set_cookie, "\x40" /* ver=1 type=con */ "\x01" /* code=GET */ "\x01\xce" /* message id (changed by set-cookie) */ "\xbb" /* ".well-known */ "\x2e\x77\x65\x6c\x6c\x2d\x6b\x6e\x6f\x77\x6e" "\x04" /* "core" */ "\x63\x6f\x72\x65" }, /* memcached "stats" request. This looks for memcached systems that can * be used for DDoS amplifiers */ {11211, 65536, 15, 0, memcached_udp_set_cookie, "\x00\x00\x00\x00\x00\x01\x00\x00stats\r\n" }, //16464,16465,16470, 16471 {16464, 65536, zeroaccess_getL_length, 0, 0, (char *)zeroaccess_getL}, {16465, 65536, zeroaccess_getL_length, 0, 0, (char *)zeroaccess_getL}, {16470, 65536, zeroaccess_getL_length, 0, 0, (char *)zeroaccess_getL}, {16471, 65536, zeroaccess_getL_length, 0, 0, (char *)zeroaccess_getL}, /* Quake 3 (amplifier) * http://blog.alejandronolla.com/2013/06/24/amplification-ddos-attack-with-quake3-servers-an-analysis-1-slash-2/ */ {27960, 65536, 0xFFFFFFFF, 0, 0, "\xFF\xFF\xFF\xFF\x67\x65\x74\x73\x74\x61\x74\x75\x73\x10"}, /* ISAKMP */ {500, 500, 352, 0, isakmp_set_cookie, /* ISAKMP */ "\x00\x11\x22\x33\x44\x55\x66\x77"/* init_cookie, overwritten on send() */ "\x00\x00\x00\x00\x00\x00\x00\x00" /* resp_cookie*/ "\x01" /* next_payload: SA */ "\x10" /* version */ "\x02" /* exch_type: identity prot. */ "\x00" /* flags */ "\x00\x00\x00\x00" /* id */ "\x00\x00\x01\x60" /* length: 352 */ /* ISAKMP_SA */ "\x00" /* next_payload: None */ "\x00" /* reserved */ "\x01\x44" /* length: 324 */ "\x00\x00\x00\x01" /* DOI: IPSEC */ "\x00\x00\x00\x01" /* situation: identity */ /* Proposal */ "\x00" /* next_payload: None */ "\x00" /* reserved */ "\x01\x38" /* length: 312 */ "\x01" /* proposal: 1 */ "\x01" /* protocol: ISAKMP */ "\x00" /* SPIsize: 0 */ "\x0d" /* trans_count: 13 */ "" /* SPI */ /* Tranforms */ "\x03" /* next_payload: Transform */ "\x00" /* reserved */ "\x00\x20" /* length: 32 */ "\x00" /* num */ "\x01" /* id: KEY_IKE */ "\x00\x00" /* reserved */ "\x80\x01\x00\x05\x80\x02\x00\x02\x80\x03\x00\x01\x80\x04\x00\x02" "\x80\x0b\x00\x01\x80\x0c\x00\x01" /* ('Encryption', '3DES-CBC'), ('Hash', 'SHA'), ('Authentication', 'PSK'), ('GroupDesc', '1024MODPgr'), ('LifeType', 'Seconds'), ('LifeDuration', 1) */ "\x03" /* next_payload: Transform */ "\x00" /* reserved */ "\x00\x20" /* length: 32 */ "\x00" /* num */ "\x01" /* id: KEY_IKE */ "\x00\x00" /* reserved */ "\x80\x01\x00\x01\x80\x02\x00\x01\x80\x03\x00\x01\x80\x04\x00\x02" "\x80\x0b\x00\x01\x80\x0c\x00\x01" /* ('Encryption', 'DES-CBC'), ('Hash', 'MD5'), ('Authentication', 'PSK'), ('GroupDesc', '1024MODPgr'), ('LifeType', 'Seconds'), ('LifeDuration', 1) */ "\x03" /* next_payload: Transform */ "\x00" /* reserved */ "\x00\x20" /* length: 32 */ "\x00" /* num */ "\x01" /* id: KEY_IKE */ "\x00\x00" /* reserved */ "\x80\x01\x00\x07\x80\x02\x00\x04\x80\x03\x00\x01\x80\x04\x00\x0e" "\x80\x0b\x00\x01\x80\x0c\x00\x01" /* ('Encryption', 'AES-CBC'), ('Hash', 'SHA2-256'), ('Authentication', 'PSK'), ('GroupDesc', '2048MODPgr'), ('LifeType', 'Seconds'), ('LifeDuration', 1) */ "\x03" /* next_payload: Transform */ "\x00" /* reserved */ "\x00\x14" /* length: 20 */ "\x00" /* num */ "\x01" /* id: KEY_IKE */ "\x00\x00" /* reserved */ "\x80\x01\x00\x05\x80\x02\x00\x02\x80\x03\x00\x02" /* ('Encryption', '3DES-CBC'), ('Hash', 'SHA'), ('Authentication', 'DSS') */ "\x03" /* next_payload: Transform */ "\x00" /* reserved */ "\x00\x14" /* length: 20 */ "\x00" /* num */ "\x01" /* id: KEY_IKE */ "\x00\x00" /* reserved */ "\x80\x01\x00\x05\x80\x02\x00\x02\x80\x03\x00\x03" /* ('Encryption', '3DES-CBC'), ('Hash', 'SHA'), ('Authentication', 'RSA Sig') */ "\x03" /* next_payload: Transform */ "\x00" /* reserved */ "\x00\x14" /* length: 20 */ "\x00" /* num */ "\x01" /* id: KEY_IKE */ "\x00\x00" /* reserved */ "\x80\x01\x00\x05\x80\x02\x00\x02\x80\x03\x00\x04" /* ('Encryption', '3DES-CBC'), ('Hash', 'SHA'), ('Authentication', 'RSA Encryption') */ "\x03" /* next_payload: Transform */ "\x00" /* reserved */ "\x00\x14" /* length: 20 */ "\x00" /* num */ "\x01" /* id: KEY_IKE */ "\x00\x00" /* reserved */ "\x80\x01\x00\x05\x80\x02\x00\x02\x80\x03\x00\x08" /* ('Encryption', '3DES-CBC'), ('Hash', 'SHA'), ('Authentication', 'ECDSA Sig') */ "\x03" /* next_payload: Transform */ "\x00" /* reserved */ "\x00\x14" /* length: 20 */ "\x00" /* num */ "\x01" /* id: KEY_IKE */ "\x00\x00" /* reserved */ "\x80\x01\x00\x05\x80\x02\x00\x02\x80\x03\xfa\xdd" /* ('Encryption', '3DES-CBC'), ('Hash', 'SHA'), ('Authentication', 'HybridInitRSA') */ "\x03" /* next_payload: Transform */ "\x00" /* reserved */ "\x00\x14" /* length: 20 */ "\x00" /* num */ "\x01" /* id: KEY_IKE */ "\x00\x00" /* reserved */ "\x80\x01\x00\x05\x80\x02\x00\x02\x80\x03\xfa\xdf" /* ('Encryption', '3DES-CBC'), ('Hash', 'SHA'), ('Authentication', 'HybridInitDSS') */ "\x03" /* next_payload: Transform */ "\x00" /* reserved */ "\x00\x14" /* length: 20 */ "\x00" /* num */ "\x01" /* id: KEY_IKE */ "\x00\x00" /* reserved */ "\x80\x01\x00\x05\x80\x02\x00\x02\x80\x03\xfd\xe9" /* ('Encryption', '3DES-CBC'), ('Hash', 'SHA'), ('Authentication', 'XAUTHInitPreShared') */ "\x03" /* next_payload: Transform */ "\x00" /* reserved */ "\x00\x14" /* length: 20 */ "\x00" /* num */ "\x01" /* id: KEY_IKE */ "\x00\x00" /* reserved */ "\x80\x01\x00\x05\x80\x02\x00\x02\x80\x03\xfd\xeb" /* ('Encryption', '3DES-CBC'), ('Hash', 'SHA'), ('Authentication', 'XAUTHInitDSS') */ "\x03" /* next_payload: Transform */ "\x00" /* reserved */ "\x00\x14" /* length: 20 */ "\x00" /* num */ "\x01" /* id: KEY_IKE */ "\x00\x00" /* reserved */ "\x80\x01\x00\x05\x80\x02\x00\x02\x80\x03\xfd\xed" /* ('Encryption', '3DES-CBC'), ('Hash', 'SHA'), ('Authentication', 'XAUTHInitRSA') */ "\x03" /* next_payload: Transform */ "\x00" /* reserved */ "\x00\x14" /* length: 20 */ "\x00" /* num */ "\x01" /* id: KEY_IKE */ "\x00\x00" /* reserved */ "\x80\x01\x00\x05\x80\x02\x00\x02\x80\x03\xfd\xef" /* ('Encryption', '3DES-CBC'), ('Hash', 'SHA'), ('Authentication', 'XAUTHInitRSAEncryption') */ "\x00" /* next_payload: None */ "\x00" /* reserved */ "\x00\x08" /* length: 8 */ "\x00" /* num */ "\x01" /* id: KEY_IKE */ "\x00\x00" /* reserved */}, {0,0,0,0,0} }; /*************************************************************************** * Calculate the partial checksum of the payload. This allows us to simply * add this to the checksum when transmitting instead of recalculating * everything. ***************************************************************************/ static unsigned partial_checksum(const unsigned char *px, size_t icmp_length) { uint64_t xsum = 0; unsigned i; for (i=0; i<icmp_length; i += 2) { xsum += px[i]<<8 | px[i + 1]; } xsum -= (icmp_length & 1) * px[i - 1]; /* yea I know going off end of packet is bad so sue me */ xsum = (xsum & 0xFFFF) + (xsum >> 16); xsum = (xsum & 0xFFFF) + (xsum >> 16); xsum = (xsum & 0xFFFF) + (xsum >> 16); return (unsigned)xsum; } /*************************************************************************** * If we have the port, return the best payload for that port. ***************************************************************************/ int payloads_udp_lookup( const struct PayloadsUDP *payloads, unsigned port, const unsigned char **px, unsigned *length, unsigned *source_port, uint64_t *xsum, SET_COOKIE *set_cookie) { unsigned i; if (payloads == 0) return 0; port &= 0xFFFF; /* This is just a linear search, done once at startup, to search * through all the payloads for the best match. */ for (i=0; i<payloads->count; i++) { if (payloads->list[i]->port == port) { *px = payloads->list[i]->buf; *length = payloads->list[i]->length; *source_port = payloads->list[i]->source_port; *xsum = payloads->list[i]->xsum; *set_cookie = payloads->list[i]->set_cookie; return 1; } } return 0; } /*************************************************************************** * cleanup on program shutdown ***************************************************************************/ void payloads_udp_destroy(struct PayloadsUDP *payloads) { unsigned i; if (payloads == NULL) return; for (i=0; i<payloads->count; i++) free(payloads->list[i]); if (payloads->list) free(payloads->list); free(payloads); } /*************************************************************************** * We read lots of UDP payloads from the files. However, we probably * aren't using most, or even any, of them. Therefore, we use this * function to remove the ones we won't be using. This makes lookups * faster, ideally looking up only zero or one rather than twenty. ***************************************************************************/ void payloads_udp_trim(struct PayloadsUDP *payloads, const struct MassIP *targets) { unsigned i; struct PayloadUDP_Item **list2; unsigned count2 = 0; /* Create a new list */ list2 = REALLOCARRAY(0, payloads->max, sizeof(list2[0])); /* Add to the new list any used ports */ for (i=0; i<payloads->count; i++) { unsigned found; found = massip_has_port(targets, payloads->list[i]->port + Templ_UDP); if (found) { list2[count2++] = payloads->list[i]; } else { free(payloads->list[i]); } //payloads->list[i] = 0; } /* Replace the old list */ free(payloads->list); payloads->list = list2; payloads->count = count2; } void payloads_oproto_trim(struct PayloadsUDP *payloads, const struct MassIP *targets) { unsigned i; struct PayloadUDP_Item **list2; unsigned count2 = 0; /* Create a new list */ list2 = REALLOCARRAY(0, payloads->max, sizeof(list2[0])); /* Add to the new list any used ports */ for (i=0; i<payloads->count; i++) { unsigned found; found = massip_has_port(targets, payloads->list[i]->port + Templ_Oproto_first); if (found) { list2[count2++] = payloads->list[i]; } else { free(payloads->list[i]); } } /* Replace the old list */ free(payloads->list); payloads->list = list2; payloads->count = count2; } /*************************************************************************** * Adds a payloads template for the indicated datagram protocol, which * is UDP or Oproto ("other IP protocol"). ***************************************************************************/ static unsigned payloads_datagram_add(struct PayloadsUDP *payloads, const unsigned char *buf, size_t length, struct RangeList *ports, unsigned source_port, SET_COOKIE set_cookie) { unsigned count = 1; struct PayloadUDP_Item *p; uint64_t port_count = rangelist_count(ports); uint64_t i; for (i=0; i<port_count; i++) { /* grow the list if we need to */ if (payloads->count + 1 > payloads->max) { size_t new_max = payloads->max*2 + 1; payloads->list = REALLOCARRAY(payloads->list, new_max, sizeof(payloads->list[0])); payloads->max = new_max; } /* allocate space for this record */ p = MALLOC(sizeof(p[0]) + length); p->port = rangelist_pick(ports, i); p->source_port = source_port; p->length = (unsigned)length; memcpy(p->buf, buf, length); p->xsum = partial_checksum(buf, length); p->set_cookie = set_cookie; /* insert in sorted order */ { unsigned j; for (j=0; j<payloads->count; j++) { if (p->port <= payloads->list[j]->port) break; } if (j < payloads->count) { if (p->port == payloads->list[j]->port) { free(payloads->list[j]); count = 0; /* don't increment count */ } else memmove(payloads->list + j + 1, payloads->list + j, (payloads->count-j) * sizeof(payloads->list[0])); } payloads->list[j] = p; payloads->count += count; count = 1; } } return count; /* zero or one */ } static unsigned payloads_datagram_add_nocookie(struct PayloadsUDP *payloads, const unsigned char *buf, size_t length, struct RangeList *ports, unsigned source_port ) { return payloads_datagram_add(payloads, buf, length, ports, source_port, 0); } /*************************************************************************** * Called during processing of the "--pcap-payloads <filename>" directive. * This is the well-known 'pcap' file format. This code strips off the * headers of the packets then preserves just the payload portion * and port number. ***************************************************************************/ void payloads_read_pcap(const char *filename, struct PayloadsUDP *payloads, struct PayloadsUDP *oproto_payloads) { struct PcapFile *pcap; unsigned count = 0; LOG(2, "payloads:'%s': opening packet capture\n", filename); /* open packet-capture */ pcap = pcapfile_openread(filename); if (pcap == NULL) { fprintf(stderr, "payloads: can't read from file '%s'\n", filename); return; } /* for all packets in the capture file * - read in packet * - parse packet * - save payload */ for (;;) { unsigned x; unsigned captured_length; unsigned char buf[65536]; struct PreprocessedInfo parsed; struct RangeList ports[1] = {{0}}; struct Range range[1] = {{0}}; /* * Read the next packet from the capture file */ { unsigned time_secs; unsigned time_usecs; unsigned original_length; x = pcapfile_readframe(pcap, &time_secs, &time_usecs, &original_length, &captured_length, buf, (unsigned)sizeof(buf)); } if (!x) break; /* * Parse the packet up to its headers */ x = preprocess_frame(buf, captured_length, 1, &parsed); if (!x) continue; /* corrupt packet */ /* * Make sure it has UDP */ switch (parsed.found) { case FOUND_DNS: case FOUND_UDP: /* * Kludge: mark the port in the format the API wants */ ports->list = range; ports->count = 1; ports->max = 1; range->begin = parsed.port_dst; range->end = range->begin; /* * Now we've completely parsed the record, so add it to our * list of payloads */ count += payloads_datagram_add( payloads, buf + parsed.app_offset, parsed.app_length, ports, 0x10000, 0); break; case FOUND_OPROTO: /* * Kludge: mark the port in the format the API wants */ ports->list = range; ports->count = 1; ports->max = 1; range->begin = parsed.ip_protocol; range->end = range->begin; /* * Now we've completely parsed the record, so add it to our * list of payloads */ count += payloads_datagram_add(oproto_payloads, buf + parsed.transport_offset, parsed.transport_length, ports, 0x10000, 0); break; default: continue; } } LOG(2, "payloads:'%s': imported %u unique payloads\n", filename, count); LOG(2, "payloads:'%s': closed packet capture\n", filename); pcapfile_close(pcap); } /*************************************************************************** * Called from the "conf" subsystem in order read in the file * "nmap-payloads". We call the function 'read_nmap_payloads()" defined * in a different file that focuses on parsing that file format. ***************************************************************************/ void payloads_udp_readfile(FILE *fp, const char *filename, struct PayloadsUDP *payloads) { read_nmap_payloads(fp, filename, payloads, payloads_datagram_add_nocookie); } /*************************************************************************** ***************************************************************************/ struct PayloadsUDP * payloads_udp_create(void) { unsigned i; struct PayloadsUDP *payloads; struct PayloadUDP_Default *hard_coded = hard_coded_udp_payloads; payloads = CALLOC(1, sizeof(*payloads)); /* * For popular parts, include some hard-coded default UDP payloads */ for (i=0; hard_coded[i].length; i++) { //struct Range range; struct RangeList list = {0}; unsigned length; /* Kludge: create a pseudo-rangelist to hold the one port */ /*list.list = &range; list.count = 1; range.begin = hard_coded[i].port; range.end = range.begin;*/ rangelist_add_range(&list, hard_coded[i].port, hard_coded[i].port); length = hard_coded[i].length; if (length == 0xFFFFFFFF) length = (unsigned)strlen(hard_coded[i].buf); /* Add this to our real payloads. This will get overwritten * if the user adds their own with the same port */ payloads_datagram_add(payloads, (const unsigned char*)hard_coded[i].buf, length, &list, hard_coded[i].source_port, hard_coded[i].set_cookie); rangelist_remove_all(&list); } return payloads; } /*************************************************************************** * (same code as for UDP) ***************************************************************************/ struct PayloadsUDP * payloads_oproto_create(void) { unsigned i; struct PayloadsUDP *payloads; struct PayloadUDP_Default *hard_coded = hard_coded_oproto_payloads; payloads = CALLOC(1, sizeof(*payloads)); /* * Some hard-coded ones, like GRE */ for (i=0; hard_coded[i].length; i++) { //struct Range range; struct RangeList list = {0}; unsigned length; /* Kludge: create a pseudo-rangelist to hold the one port */ rangelist_add_range(&list, hard_coded[i].port, hard_coded[i].port); length = hard_coded[i].length; if (length == 0xFFFFFFFF) length = (unsigned)strlen(hard_coded[i].buf); /* Add this to our real payloads. This will get overwritten * if the user adds their own with the same port */ payloads_datagram_add(payloads, (const unsigned char*)hard_coded[i].buf, length, &list, hard_coded[i].source_port, hard_coded[i].set_cookie); rangelist_remove_all(&list); } return payloads; } int templ_payloads_selftest(void) { return templ_nmap_selftest(); }
31,517
C
.c
807
30.444857
117
0.506918
robertdavidgraham/masscan
23,250
3,042
399
AGPL-3.0
9/7/2024, 9:40:14 AM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
5,412
util-safefunc.c
robertdavidgraham_masscan/src/util-safefunc.c
/* safe C library functions This upgrades unsafe C functions like "strcpy()" to safer equivalents, like "safe_strcpy()". NOTE: This is for maintaining a policy of "no unsafe functions" */ #include "util-safefunc.h" #include <errno.h> #include <ctype.h> #include <errno.h> #include <string.h> /** * Case-insensitive memcmp() */ #ifdef __GNUC__ int memcasecmp(const void *lhs, const void *rhs, size_t length) { int i; for (i=0; i<length; i++) { if (tolower(((char*)lhs)[i]) != tolower(((char*)rhs)[i])) return -1; } return 0; } #endif /** * Safe version of `strcpy()` */ void safe_strcpy(char *dst, size_t sizeof_dst, const char *src) { size_t i; if (sizeof_dst == 0) return; if (dst == NULL) return; if (src == NULL) { dst[0] = 0; return; } for (i=0; src[i]; i++) { if (i >= sizeof_dst) { dst[0] = 0; return; } else dst[i] = src[i]; } if (i >= sizeof_dst) { dst[0] = 0; return ; } else dst[i] = src[i]; return; } int safe_localtime(struct tm* _tm, const time_t *time) { struct tm *x; x = localtime(time); if (x == NULL) { memset(_tm, 0, sizeof(*_tm)); return -1; } memcpy(_tm, x, sizeof(*_tm)); return 0; } int safe_gmtime(struct tm* _tm, const time_t *time) { struct tm *x; x = gmtime(time); if (x == NULL) { memset(_tm, 0, sizeof(*_tm)); return -1; } memcpy(_tm, x, sizeof(*_tm)); return 0; }
1,598
C
.c
79
15.379747
74
0.534356
robertdavidgraham/masscan
23,250
3,042
399
AGPL-3.0
9/7/2024, 9:40:14 AM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
5,417
out-tcp-services.h
robertdavidgraham_masscan/src/out-tcp-services.h
#ifndef OUT_TCP_SERVICES_H #define OUT_TCP_SERVICES_H const char *tcp_service_name(int port); const char *udp_service_name(int port); const char *oproto_service_name(int protocol_number); #endif
198
C
.c
6
31.5
53
0.793651
robertdavidgraham/masscan
23,250
3,042
399
AGPL-3.0
9/7/2024, 9:40:14 AM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
5,419
util-safefunc.h
robertdavidgraham_masscan/src/util-safefunc.h
/* safe "string" functions This is for the "safe" clib functions, where things like "strcpy()" is replaced with a safer version of the function, like "safe_strcpy()". NOTE: I tried to based these on Microosft's `..._s()` functions proposed in Annex K, but it's become too hard trying to deal with both my own version and existing versions. Therefore, I've changed this code to use names not used by others. Reference: http://msdn.microsoft.com/en-us/library/bb288454.aspx */ #ifndef UTIL_SAFEFUNC_H #define UTIL_SAFEFUNC_H #include <errno.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <time.h> #include <stdint.h> #ifdef _MSC_VER #pragma warning(disable: 4996) #endif #undef strcpy #define strcpy STRCPY_FUNCTION_IS_BAD /*#undef strncpy #define strncpy STRNCPY_FUNCTION_IS_BAD*/ #undef strcat #define strcat STRCAT_FUNCTION_IS_BAD #undef strncat #define strncat STRNCAT_FUNCTION_IS_BAD #undef sprintf #define sprintf SPRINTF_FUNCTION_IS_BAD #undef vsprintf #define vsprintf VSPRINTF_FUNCTION_IS_BAD #undef strtok #define strtok STRTOK_FUNCTION_IS_BAD #undef gets #define gets GETS_FUNCTION_IS_BAD #undef scanf #define scanf SCANF_FUNCTION_IS_BAD #undef sscanf #define sscanf SSCANF_FUNCTION_IS_BAD #undef itoa #define itoa ITOA_FUNCTION_IS_BAD /** * A bounds checking version of strcpy, like `strcpy_s()` on Windows or * `strlcpy()` in glibc. */ void safe_strcpy(char *dst, size_t sizeof_dst, const char *src); int safe_localtime(struct tm* _tm, const time_t *time); int safe_gmtime(struct tm* _tm, const time_t *time); #if defined(_MSC_VER) && (_MSC_VER >= 1900) /*Visual Studio 2015 and 2017*/ # include <stdio.h> # include <string.h> # define strcasecmp _stricmp # define memcasecmp _memicmp # ifndef PRIu64 # define PRIu64 "llu" # define PRId64 "lld" # define PRIx64 "llx" # endif #elif defined(_MSC_VER) && (_MSC_VER == 1600) /*Visual Studio 2010*/ # include <stdio.h> # include <string.h> #pragma warning(disable: 4996) #define snprintf _snprintf # define strcasecmp _stricmp # define memcasecmp _memicmp # ifndef PRIu64 # define PRIu64 "llu" # define PRId64 "lld" # define PRIx64 "llx" # endif #elif defined(_MSC_VER) && (_MSC_VER == 1200) /* Visual Studio 6.0 */ # define snprintf _snprintf # define strcasecmp _stricmp # define memcasecmp _memicmp # define vsnprintf _vsnprintf #elif defined(__GNUC__) && (__GNUC__ >= 4) #include <inttypes.h> int memcasecmp(const void *lhs, const void *rhs, size_t length);; #else # warning unknown compiler #endif #endif
2,646
C
.c
88
28.363636
76
0.722134
robertdavidgraham/masscan
23,250
3,042
399
AGPL-3.0
9/7/2024, 9:40:14 AM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
5,426
out-binary.c
robertdavidgraham_masscan/src/out-binary.c
#include "output.h" #include "masscan-app.h" #include "masscan-status.h" #include "out-record.h" #include "util-safefunc.h" #include <assert.h> /**************************************************************************** ****************************************************************************/ static void binary_out_open(struct Output *out, FILE *fp) { char firstrecord[2+'a']; size_t bytes_written; UNUSEDPARM(out); memset(firstrecord, 0, 2+'a'); snprintf(firstrecord, 2+'a', "masscan/1.1\ns:%u\n", (unsigned)out->when_scan_started); bytes_written = fwrite(firstrecord, 1, 2+'a', fp); if (bytes_written != 2+'a') { perror("output"); exit(1); } out->rotate.bytes_written += bytes_written; } /**************************************************************************** ****************************************************************************/ static void binary_out_close(struct Output *out, FILE *fp) { char firstrecord[2+'a']; size_t bytes_written; UNUSEDPARM(out); memset(firstrecord, 0, 2+'a'); snprintf(firstrecord, 2+'a', "masscan/1.1"); bytes_written = fwrite(firstrecord, 1, 2+'a', fp); if (bytes_written != 2+'a') { perror("output"); exit(1); } out->rotate.bytes_written += bytes_written; } static void _put_byte(unsigned char *buf, size_t length, size_t *r_offset, unsigned long long num) { size_t offset = *r_offset; (*r_offset) += 1; if (*r_offset <= length) { buf[offset++] = (unsigned char)(num>>0); } } static void _put_short(unsigned char *buf, size_t length, size_t *r_offset, unsigned long long num) { size_t offset = *r_offset; (*r_offset) += 2; if (*r_offset <= length) { buf[offset++] = (unsigned char)(num>>8); buf[offset++] = (unsigned char)(num>>0); } } static void _put_integer(unsigned char *buf, size_t length, size_t *r_offset, unsigned long long num) { size_t offset = *r_offset; (*r_offset) += 4; if (*r_offset <= length) { buf[offset++] = (unsigned char)(num>>24); buf[offset++] = (unsigned char)(num>>16); buf[offset++] = (unsigned char)(num>>8); buf[offset++] = (unsigned char)(num>>0); } } static void _put_long(unsigned char *buf, size_t length, size_t *r_offset, unsigned long long num) { size_t offset = *r_offset; (*r_offset) += 8; if (*r_offset <= length) { buf[offset++] = (unsigned char)(num>>56); buf[offset++] = (unsigned char)(num>>48); buf[offset++] = (unsigned char)(num>>40); buf[offset++] = (unsigned char)(num>>32); buf[offset++] = (unsigned char)(num>>24); buf[offset++] = (unsigned char)(num>>16); buf[offset++] = (unsigned char)(num>>8); buf[offset++] = (unsigned char)(num>>0); } } /**************************************************************************** ****************************************************************************/ static void binary_out_status_ipv6(struct Output *out, FILE *fp, time_t timestamp, int status, ipaddress ip, unsigned ip_proto, unsigned port, unsigned reason, unsigned ttl) { unsigned char buf[256+1]; size_t max = sizeof(buf)-1; size_t offset = 0; size_t bytes_written; /* [TYPE] field */ switch (status) { case PortStatus_Open: _put_byte(buf, max, &offset, Out_Open6); break; case PortStatus_Closed: _put_byte(buf, max, &offset, Out_Closed6); break; case PortStatus_Arp: _put_byte(buf, max, &offset, Out_Arp6); break; default: return; } /* [LENGTH] field * see assert() below */ _put_byte(buf, max, &offset, 26); _put_integer(buf, max, &offset, timestamp); _put_byte(buf, max, &offset, ip_proto); _put_short(buf, max, &offset, port); _put_byte(buf, max, &offset, reason); _put_byte(buf, max, &offset, ttl); _put_byte(buf, max, &offset, ip.version); _put_long(buf, max, &offset, ip.ipv6.hi); _put_long(buf, max, &offset, ip.ipv6.lo); assert(offset == 2 + 26); bytes_written = fwrite(buf, 1, offset, fp); if (bytes_written != offset) { perror("output"); exit(1); } out->rotate.bytes_written += bytes_written; } /**************************************************************************** ****************************************************************************/ static void binary_out_status(struct Output *out, FILE *fp, time_t timestamp, int status, ipaddress ip, unsigned ip_proto, unsigned port, unsigned reason, unsigned ttl) { unsigned char foo[256]; size_t bytes_written; /* This function is for IPv6, call a different function for IPv6 */ if (ip.version == 6) { binary_out_status_ipv6(out, fp, timestamp, status, ip, ip_proto, port, reason, ttl); return; } /* [TYPE] field */ switch (status) { case PortStatus_Open: foo[0] = Out_Open2; break; case PortStatus_Closed: foo[0] = Out_Closed2; break; case PortStatus_Arp: foo[0] = Out_Arp2; break; default: return; } /* [LENGTH] field */ foo[1] = 13; /* [TIMESTAMP] field */ foo[2] = (unsigned char)(timestamp>>24); foo[3] = (unsigned char)(timestamp>>16); foo[4] = (unsigned char)(timestamp>> 8); foo[5] = (unsigned char)(timestamp>> 0); foo[6] = (unsigned char)(ip.ipv4 >>24); foo[7] = (unsigned char)(ip.ipv4 >>16); foo[8] = (unsigned char)(ip.ipv4 >> 8); foo[9] = (unsigned char)(ip.ipv4 >> 0); foo[10] = (unsigned char)(ip_proto); foo[11] = (unsigned char)(port>>8); foo[12] = (unsigned char)(port>>0); foo[13] = (unsigned char)reason; foo[14] = (unsigned char)ttl; bytes_written = fwrite(&foo, 1, 15, fp); if (bytes_written != 15) { perror("output"); exit(1); } out->rotate.bytes_written += bytes_written; } /**************************************************************************** ****************************************************************************/ static void binary_out_banner_ipv6(struct Output *out, FILE *fp, time_t timestamp, ipaddress ip, unsigned ip_proto, unsigned port, enum ApplicationProtocol proto, unsigned ttl, const unsigned char *px, unsigned length) { unsigned char foo[32768]; unsigned i; size_t bytes_written; static const unsigned HeaderLength = 14 + 13; /* [TYPE] field */ foo[0] = Out_Banner6; /*banner*/ /* [LENGTH] field*/ if (length >= 128 * 128 - HeaderLength) return; if (length < 128 - HeaderLength) { foo[1] = (unsigned char)(length + HeaderLength); i = 2; } else { foo[1] = (unsigned char)((length + HeaderLength)>>7) | 0x80; foo[2] = (unsigned char)((length + HeaderLength) & 0x7F); i = 3; } /* [TIMESTAMP] field */ foo[i+0] = (unsigned char)(timestamp>>24); foo[i+1] = (unsigned char)(timestamp>>16); foo[i+2] = (unsigned char)(timestamp>> 8); foo[i+3] = (unsigned char)(timestamp>> 0); foo[i+ 4] = (unsigned char)(ip_proto); foo[i+ 5] = (unsigned char)(port>>8); foo[i+ 6] = (unsigned char)(port>>0); foo[i+ 7] = (unsigned char)(proto>>8); foo[i+ 8] = (unsigned char)(proto>>0); foo[i+ 9] = (unsigned char)(ttl); foo[i+10] = (unsigned char)(ip.version); foo[i+11] = (unsigned char)(ip.ipv6.hi >> 56ULL); foo[i+12] = (unsigned char)(ip.ipv6.hi >> 48ULL); foo[i+13] = (unsigned char)(ip.ipv6.hi >> 40ULL); foo[i+14] = (unsigned char)(ip.ipv6.hi >> 32ULL); foo[i+15] = (unsigned char)(ip.ipv6.hi >> 24ULL); foo[i+16] = (unsigned char)(ip.ipv6.hi >> 16ULL); foo[i+17] = (unsigned char)(ip.ipv6.hi >> 8ULL); foo[i+18] = (unsigned char)(ip.ipv6.hi >> 0ULL); foo[i+19] = (unsigned char)(ip.ipv6.lo >> 56ULL); foo[i+20] = (unsigned char)(ip.ipv6.lo >> 48ULL); foo[i+21] = (unsigned char)(ip.ipv6.lo >> 40ULL); foo[i+22] = (unsigned char)(ip.ipv6.lo >> 32ULL); foo[i+23] = (unsigned char)(ip.ipv6.lo >> 24ULL); foo[i+24] = (unsigned char)(ip.ipv6.lo >> 16ULL); foo[i+25] = (unsigned char)(ip.ipv6.lo >> 8ULL); foo[i+26] = (unsigned char)(ip.ipv6.lo >> 0ULL); /* Banner */ memcpy(foo+i+14+13, px, length); bytes_written = fwrite(&foo, 1, length+i+HeaderLength, fp); if (bytes_written != length+i+HeaderLength) { perror("output"); exit(1); } out->rotate.bytes_written += bytes_written; } /**************************************************************************** ****************************************************************************/ static void binary_out_banner(struct Output *out, FILE *fp, time_t timestamp, ipaddress ip, unsigned ip_proto, unsigned port, enum ApplicationProtocol proto, unsigned ttl, const unsigned char *px, unsigned length) { unsigned char foo[32768]; unsigned i; size_t bytes_written; static const unsigned HeaderLength = 14; if (ip.version == 6) { binary_out_banner_ipv6(out, fp, timestamp, ip, ip_proto, port, proto, ttl, px, length); return; } /* [TYPE] field */ foo[0] = Out_Banner9; /*banner*/ /* [LENGTH] field*/ if (length >= 128 * 128 - HeaderLength) return; if (length < 128 - HeaderLength) { foo[1] = (unsigned char)(length + HeaderLength); i = 2; } else { foo[1] = (unsigned char)((length + HeaderLength)>>7) | 0x80; foo[2] = (unsigned char)((length + HeaderLength) & 0x7F); i = 3; } /* [TIMESTAMP] field */ foo[i+0] = (unsigned char)(timestamp>>24); foo[i+1] = (unsigned char)(timestamp>>16); foo[i+2] = (unsigned char)(timestamp>> 8); foo[i+3] = (unsigned char)(timestamp>> 0); foo[i+4] = (unsigned char)(ip.ipv4 >> 24); foo[i+5] = (unsigned char)(ip.ipv4 >> 16); foo[i+6] = (unsigned char)(ip.ipv4 >> 8); foo[i+7] = (unsigned char)(ip.ipv4 >> 0); foo[i+8] = (unsigned char)(ip_proto); foo[i+ 9] = (unsigned char)(port>>8); foo[i+10] = (unsigned char)(port>>0); foo[i+11] = (unsigned char)(proto>>8); foo[i+12] = (unsigned char)(proto>>0); foo[i+13] = (unsigned char)(ttl); /* Banner */ memcpy(foo+i+14, px, length); bytes_written = fwrite(&foo, 1, length+i+HeaderLength, fp); if (bytes_written != length+i+HeaderLength) { perror("output"); exit(1); } out->rotate.bytes_written += bytes_written; } /**************************************************************************** ****************************************************************************/ const struct OutputType binary_output = { "scan", 0, binary_out_open, binary_out_close, binary_out_status, binary_out_banner, };
10,963
C
.c
306
30.506536
95
0.533661
robertdavidgraham/masscan
23,250
3,042
399
AGPL-3.0
9/7/2024, 9:40:14 AM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
5,428
masscan-app.c
robertdavidgraham_masscan/src/masscan-app.c
#include "masscan-app.h" #include "util-safefunc.h" /****************************************************************************** * When outputting results, we call this function to print out the type of * banner that we've collected ******************************************************************************/ const char * masscan_app_to_string(enum ApplicationProtocol proto) { static char tmp[64]; switch (proto) { case PROTO_NONE: return "unknown"; case PROTO_HEUR: return "unknown"; case PROTO_SSH1: return "ssh"; case PROTO_SSH2: return "ssh"; case PROTO_HTTP: return "http"; case PROTO_FTP: return "ftp"; case PROTO_DNS_VERSIONBIND: return "dns-ver"; case PROTO_SNMP: return "snmp"; case PROTO_NBTSTAT: return "nbtstat"; case PROTO_SSL3: return "ssl"; case PROTO_SMB: return "smb"; case PROTO_SMTP: return "smtp"; case PROTO_POP3: return "pop"; case PROTO_IMAP4: return "imap"; case PROTO_UDP_ZEROACCESS: return "zeroaccess"; case PROTO_X509_CERT: return "X509"; case PROTO_X509_CACERT: return "X509CA"; case PROTO_HTML_TITLE: return "title"; case PROTO_HTML_FULL: return "html"; case PROTO_NTP: return "ntp"; case PROTO_VULN: return "vuln"; case PROTO_HEARTBLEED: return "heartbleed"; case PROTO_TICKETBLEED: return "ticketbleed"; case PROTO_VNC_OLD: return "vnc"; case PROTO_SAFE: return "safe"; case PROTO_MEMCACHED: return "memcached"; case PROTO_SCRIPTING: return "scripting"; case PROTO_VERSIONING: return "versioning"; case PROTO_COAP: return "coap"; case PROTO_TELNET: return "telnet"; case PROTO_RDP: return "rdp"; case PROTO_HTTP_SERVER: return "http.server"; case PROTO_MC: return "minecraft"; case PROTO_VNC_RFB: return "vnc"; case PROTO_VNC_INFO: return "vnc-info"; case PROTO_ISAKMP: return "isakmp"; case PROTO_ERROR: return "error"; default: snprintf(tmp, sizeof(tmp), "(%u)", proto); return tmp; } } /****************************************************************************** ******************************************************************************/ enum ApplicationProtocol masscan_string_to_app(const char *str) { const static struct { const char *name; enum ApplicationProtocol value; } list[] = { {"ssh1", PROTO_SSH1}, {"ssh2", PROTO_SSH2}, {"ssh", PROTO_SSH2}, {"http", PROTO_HTTP}, {"ftp", PROTO_FTP}, {"dns-ver", PROTO_DNS_VERSIONBIND}, {"snmp", PROTO_SNMP}, {"nbtstat", PROTO_NBTSTAT}, {"ssl", PROTO_SSL3}, {"smtp", PROTO_SMTP}, {"smb", PROTO_SMB}, {"pop", PROTO_POP3}, {"imap", PROTO_IMAP4}, {"x509", PROTO_X509_CERT}, {"x509ca", PROTO_X509_CACERT}, {"zeroaccess", PROTO_UDP_ZEROACCESS}, {"title", PROTO_HTML_TITLE}, {"html", PROTO_HTML_FULL}, {"ntp", PROTO_NTP}, {"vuln", PROTO_VULN}, {"heartbleed", PROTO_HEARTBLEED}, {"ticketbleed", PROTO_TICKETBLEED}, {"vnc-old", PROTO_VNC_OLD}, {"safe", PROTO_SAFE}, {"memcached", PROTO_MEMCACHED}, {"scripting", PROTO_SCRIPTING}, {"versioning", PROTO_VERSIONING}, {"coap", PROTO_COAP}, {"telnet", PROTO_TELNET}, {"rdp", PROTO_RDP}, {"http.server", PROTO_HTTP_SERVER}, {"minecraft", PROTO_MC}, {"vnc", PROTO_VNC_RFB}, {"vnc-info", PROTO_VNC_INFO}, {"isakmp", PROTO_ISAKMP}, {0,0} }; size_t i; for (i=0; list[i].name; i++) { if (strcmp(str, list[i].name) == 0) return list[i].value; } return 0; } int masscan_app_selftest(void) { static const struct { unsigned enumid; unsigned expected; } tests[] = { {PROTO_SNMP, 7}, {PROTO_X509_CERT, 15}, {PROTO_HTTP_SERVER, 31}, {0,0} }; size_t i; /* The ENUM contains fixed values in external files, * so programmers should only add onto its end, not * the middle. This self-test will verify that * a programmer hasn't made this mistake. */ for (i=0; tests[i].enumid != 0; i++) { unsigned enumid = tests[i].enumid; unsigned expected = tests[i].expected; /* YOU ADDED AN ENUM IN THE MIDDLE INSTEAD ON THE END OF THE LIST */ if (enumid != expected) { fprintf(stderr, "[-] %s:%u fail\n", __FILE__, (unsigned)__LINE__); fprintf(stderr, "[-] enum expected=%u, found=%u\n", 30, PROTO_HTTP_SERVER); return 1; } } return 0; }
4,948
C
.c
135
30.02963
87
0.528844
robertdavidgraham/masscan
23,250
3,042
399
AGPL-3.0
9/7/2024, 9:40:14 AM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
5,432
stack-ndpv6.c
robertdavidgraham_masscan/src/stack-ndpv6.c
#include "stack-ndpv6.h" #include "proto-preprocess.h" #include "stack-src.h" #include "util-checksum.h" #include "rawsock-adapter.h" #include "rawsock.h" #include "util-logger.h" #include <string.h> static inline void _append(unsigned char *buf, size_t *r_offset, size_t max, unsigned x) { if (*r_offset >= max) return; buf[(*r_offset)++] = (unsigned char)x; } static inline void _append_bytes(unsigned char *buf, size_t *r_offset, size_t max, const void *v_bytes, size_t len) { const unsigned char *bytes = (const unsigned char *)v_bytes; if (*r_offset + len >= max) return; memcpy(buf + *r_offset, bytes, len); *r_offset += len; } static inline void _append_short(unsigned char *buf, size_t *offset, size_t max, unsigned num) { if (2 > max - *offset) { *offset = max; return; } buf[(*offset)++] = (unsigned char)(num>>8); buf[(*offset)++] = (unsigned char)(num & 0xFF); } static inline unsigned _read_byte(const unsigned char *buf, size_t *offset, size_t max) { if (*offset + 1 < max) { return buf[(*offset)++]; } else return (unsigned)~0; } static inline unsigned _read_short(const unsigned char *buf, size_t *offset, size_t max) { if (*offset + 2 <= max) { unsigned result; result = buf[(*offset)++] << 8; result |= buf[(*offset)++]; return result; } else return (unsigned)~0; } static inline unsigned _read_number(const unsigned char *buf, size_t *offset, size_t max) { if (*offset + 4 <= max) { unsigned result; result = buf[(*offset)++] << 24; result |= buf[(*offset)++] << 16; result |= buf[(*offset)++] << 8; result |= buf[(*offset)++]; return result; } else return (unsigned)~0; } static inline ipv6address_t _read_ipv6(const unsigned char *buf, size_t *offset, size_t max) { ipv6address_t result = {0,0}; if (*offset + 16 <= max) { result = ipv6address_from_bytes(buf + *offset); *offset += 16; } else { *offset = max; } return result; } /** * Handle the IPv6 Neighbor Solicitation request. * This happens after we've transmitted a packet, a response is on * it's way back, and the router needs to give us the response * packet. The router sends us a solicitation, like an ARP request, * to which we must respond. */ int stack_ndpv6_incoming_request(struct stack_t *stack, struct PreprocessedInfo *parsed, const unsigned char *px, size_t length) { struct PacketBuffer *response = 0; size_t offset; size_t remaining; ipaddress target_ip; const unsigned char *target_ip_buf; macaddress_t target_mac = stack->source_mac; unsigned xsum; unsigned char *buf2; static const size_t max = sizeof(response->px); size_t offset_ip = parsed->ip_offset; size_t offset_ip_src = offset_ip + 8; /* offset in packet to the source IPv6 address */ size_t offset_ip_dst = offset_ip + 24; size_t offset_icmpv6 = parsed->transport_offset; /* Verify it's a "Neighbor Solitication" opcode */ if (parsed->opcode != 135) return -1; /* Make sure there's at least a full header */ offset = parsed->transport_offset; remaining = length - offset; if (remaining < 24) return -1; /* Make sure it's looking for our own address */ target_ip_buf = px + offset + 8; target_ip.version = 6; target_ip.ipv6 = ipv6address_from_bytes(target_ip_buf); if (!is_my_ip(stack->src, target_ip)) return -1; /* Print a log message */ { ipv6address_t a = ipv6address_from_bytes(px + offset_ip_src); ipaddress_formatted_t fmt1 = ipv6address_fmt(a); ipaddress_formatted_t fmt2 = ipaddress_fmt(target_ip); LOG(1, "[+] received NDP request from %s for %s\n", fmt1.string, fmt2.string); } /* Get a buffer for sending the response packet. This thread doesn't * send the packet itself. Instead, it formats a packet, then hands * that packet off to a transmit thread for later transmission. */ response = stack_get_packetbuffer(stack); if (response == NULL) return -1; /* Use the request packet as a template for the response */ memcpy(response->px, px, length); buf2 = response->px; /* Set the destination MAC address and destination IPv6 address*/ memcpy(buf2 + 0, px + 6, 6); memcpy(buf2 + offset_ip_dst, px + offset_ip_src, 16); /* Set the source MAC address and source IPv6 address */ memcpy(buf2 + offset_ip_src, target_ip_buf, 16); memcpy(buf2 + 6, target_mac.addr, 6); /* Format the response */ _append(buf2, &offset, max, 136); /* type */ _append(buf2, &offset, max, 0); /* code */ _append(buf2, &offset, max, 0); /*checksum[hi] */ _append(buf2, &offset, max, 0); /*checksum[lo] */ _append(buf2, &offset, max, 0x60); /* flags*/ _append(buf2, &offset, max, 0); _append(buf2, &offset, max, 0); _append(buf2, &offset, max, 0); _append_bytes(buf2, &offset, max, target_ip_buf, 16); _append(buf2, &offset, max, 2); _append(buf2, &offset, max, 1); _append_bytes(buf2, &offset, max, target_mac.addr, 6); xsum = checksum_ipv6( buf2 + offset_ip_src, buf2 + offset_ip_dst, 58, offset - offset_icmpv6, buf2 +offset_icmpv6); buf2[offset_icmpv6 + 2] = (unsigned char)(xsum >> 8); buf2[offset_icmpv6 + 3] = (unsigned char)(xsum >> 0); /* Transmit the packet-buffer */ response->length = offset; stack_transmit_packetbuffer(stack, response); return 0; } static int _extract_router_advertisement( const unsigned char *buf, size_t length, struct PreprocessedInfo *parsed, ipv6address my_ipv6, ipv6address *router_ip, macaddress_t *router_mac) { size_t offset; int is_same_prefix = 1; int is_mac_explicit = 0; if (parsed->ip_version != 6) return 1; *router_ip = parsed->src_ip.ipv6; if (parsed->ip_protocol != 58) return 1; offset = parsed->transport_offset; /* type = Router Advertisement */ if (_read_byte(buf, &offset, length) != 134) return 1; /* code = 0 */ if (_read_byte(buf, &offset, length) != 0) return 1; /* checksum */ _read_short(buf, &offset, length); /* hop limit */ _read_byte(buf, &offset, length); /* flags */ _read_byte(buf, &offset, length); /* router life time */ _read_short(buf, &offset, length); /* reachable time */ _read_number(buf, &offset, length); /* retrans timer */ _read_number(buf, &offset, length); while (offset + 8 <= length) { unsigned type = buf[offset + 0]; size_t len2 = buf[offset + 1] * 8; size_t off2 = 2; const unsigned char *buf2 = buf + offset; switch (type) { case 3: /* prefix info */ { unsigned prefix_len; ipv6address prefix; ipaddress_formatted_t fmt; prefix_len = _read_byte(buf2, &off2, len2); _read_byte(buf2, &off2, len2); /* flags */ _read_number(buf2, &off2, len2); /* valid lifetime */ _read_number(buf2, &off2, len2); /* preferred lifetime */ _read_number(buf2, &off2, len2); /* reserved */ prefix = _read_ipv6(buf2, &off2, len2); fmt = ipv6address_fmt(prefix); LOG(1, "[+] IPv6.prefix = %s/%u\n", fmt.string, prefix_len); if (ipv6address_is_equal_prefixed(my_ipv6, prefix, prefix_len)) { is_same_prefix = 1; } else { ipaddress_formatted_t fmt1 = ipv6address_fmt(my_ipv6); ipaddress_formatted_t fmt2 = ipv6address_fmt(prefix); LOG(0, "[-] WARNING: our source-ip is %s, but router prefix announces %s/%u\n", fmt1.string, fmt2.string, prefix_len); is_same_prefix = 0; } } break; case 25: /* recursive DNS server */ _read_short(buf2, &off2, len2); _read_number(buf2, &off2, len2); while (off2 + 16 <= len2) { ipv6address resolver = _read_ipv6(buf2, &off2, len2); ipaddress_formatted_t fmt = ipv6address_fmt(resolver); LOG(1, "[+] IPv6.DNS = %s\n", fmt.string); } break; case 1: if (len2 == 8) { memcpy(router_mac->addr, buf2 + 2, 6); is_mac_explicit = 1; } break; } offset += len2; } if (!is_mac_explicit) { /* The router advertisement didn't include an explicit * source address. Therefore, pull the response from * the Ethernet header of the packet instead */ memcpy(router_mac->addr, parsed->mac_src, 6); } if (!is_same_prefix) { /* We had a valid router advertisement, but it didn't * match the IPv6 address we are using. This presumably * means there are multiple possible IPv6 routers on the * network. Therefore, we are going to discard this * packet and wait for another one */ return 1; } return 0; } /**************************************************************************** ****************************************************************************/ int stack_ndpv6_resolve(struct Adapter *adapter, ipv6address my_ipv6, macaddress_t my_mac_address, macaddress_t *router_mac) { unsigned char buf[128]; size_t max = sizeof(buf); size_t offset = 0; unsigned i; time_t start; unsigned is_arp_notice_given = 0; int is_delay_reported = 0; size_t offset_ip; size_t offset_ip_src; size_t offset_ip_dst; size_t offset_icmpv6; unsigned xsum; struct PreprocessedInfo parsed = {0}; /* * [KLUDGE] * If this is a VPN connection, then there is no answer */ if (stack_if_datalink(adapter) == 12) { memcpy(router_mac->addr, "\0\0\0\0\0\2", 6); return 0; /* success */ } /* * Ethernet header */ _append_bytes(buf, &offset, max, "\x33\x33\x00\x00\x00\x02", 6); _append_bytes(buf, &offset, max, my_mac_address.addr, 6); if (adapter->is_vlan) { _append_short(buf, &offset, max, 0x8100); _append_short(buf, &offset, max, adapter->vlan_id); } _append_short(buf, &offset, max, 0x86dd); /* * Create IPv6 header */ offset_ip = offset; _append(buf, &offset, max, 0x60); /* version = 6 */ _append(buf, &offset, max, 0); _append_short(buf, &offset, max, 0); _append_short(buf, &offset, max, 0); /* length = 0 */ _append(buf, &offset, max, 58); /* proto = ICMPv6 */ _append(buf, &offset, max, 255); /*hop limit = 255 */ /* Link local source address based on MAC address */ offset_ip_src = offset; _append_short(buf, &offset, max, 0xfe80); _append_short(buf, &offset, max, 0); _append_short(buf, &offset, max, 0); _append_short(buf, &offset, max, 0); _append_bytes(buf, &offset, max, my_mac_address.addr, 3); buf[offset-3] |= 2; _append_short(buf, &offset, max, 0xfffe); _append_bytes(buf, &offset, max, my_mac_address.addr+3, 3); /* All-routers link local address */ offset_ip_dst = offset; _append_short(buf, &offset, max, 0xff02); _append_short(buf, &offset, max, 0); _append_short(buf, &offset, max, 0); _append_short(buf, &offset, max, 0); _append_short(buf, &offset, max, 0); _append_short(buf, &offset, max, 0); _append_short(buf, &offset, max, 0); _append_short(buf, &offset, max, 2); /* ICMPv6 Router Solicitation */ offset_icmpv6 = offset; _append(buf, &offset, max, 133); /* type = Router Solicitation */ _append(buf, &offset, max, 0); _append_short(buf, &offset, max, 0); /* checksum = 0 (for the moment) */ _append_short(buf, &offset, max, 0); /* reserved */ _append_short(buf, &offset, max, 0); /* reserved */ _append(buf, &offset, max, 1); /* option = source link layer address */ _append(buf, &offset, max, 1); /* length = 2 + 6 / 8*/ _append_bytes(buf, &offset, max, my_mac_address.addr, 6); buf[offset_ip + 4] = (unsigned char)( (offset - offset_icmpv6) >> 8); buf[offset_ip + 5] = (unsigned char)( (offset - offset_icmpv6) & 0xFF); xsum = checksum_ipv6( buf + offset_ip_src, buf + offset_ip_dst, 58, offset - offset_icmpv6, buf + offset_icmpv6); buf[offset_icmpv6 + 2] = (unsigned char)(xsum >> 8); buf[offset_icmpv6 + 3] = (unsigned char)(xsum >> 0); rawsock_send_packet(adapter, buf, (unsigned)offset, 1); /* * Send a shorter version after the long version. I don't know * why, but some do this on the Internet. */ offset -= 8; buf[offset_ip + 4] = (unsigned char)( (offset - offset_icmpv6) >> 8); buf[offset_ip + 5] = (unsigned char)( (offset - offset_icmpv6) & 0xFF); xsum = checksum_ipv6( buf + offset_ip_src, buf + offset_ip_dst, 58, offset - offset_icmpv6, buf + offset_icmpv6); buf[offset_icmpv6 + 2] = (unsigned char)(xsum >> 8); buf[offset_icmpv6 + 3] = (unsigned char)(xsum >> 0); rawsock_send_packet(adapter, buf, (unsigned)offset, 1); start = time(0); i = 0; for (;;) { unsigned length2; unsigned secs; unsigned usecs; const unsigned char *buf2; int err; ipv6address router_ip; /* Resend every so often */ if (time(0) != start) { start = time(0); rawsock_send_packet(adapter, buf, (unsigned)offset, 1); if (i++ >= 10) break; /* timeout */ /* It's taking too long, so notify the user */ if (!is_delay_reported) { fprintf(stderr, "[ ] resolving IPv6 router MAC address (may take some time)...\n"); is_delay_reported = 1; } } /* If we aren't getting a response back to our ARP, then print a * status message */ if (time(0) > start+1 && !is_arp_notice_given) { fprintf(stderr, "[ ] resolving local IPv6 router\n"); is_arp_notice_given = 1; } err = rawsock_recv_packet( adapter, &length2, &secs, &usecs, &buf2); if (err != 0) continue; /* * Parse the packet. We'll get lots of packets we aren't interested * in,so we'll just loop around and keep searching until we find * one. */ err = preprocess_frame(buf2, length2, 1, &parsed); if (err != 1) continue; if (parsed.found != FOUND_NDPv6) continue; /* We've found a packet that may be the one we want, so parse it */ err = _extract_router_advertisement(buf2, length2, &parsed, my_ipv6, &router_ip, router_mac); if (err) continue; /* The previous call found 'router_mac", so now return */ return 0; } return 1; }
15,823
C
.c
418
29.58134
125
0.563175
robertdavidgraham/masscan
23,250
3,042
399
AGPL-3.0
9/7/2024, 9:40:14 AM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
5,435
stack-tcp-app.h
robertdavidgraham_masscan/src/stack-tcp-app.h
#ifndef STACK_TCP_APP_H #define STACK_TCP_APP_H #include <stdio.h> #include "util-bool.h" /* <stdbool.h> */ struct stack_handle_t; struct ProtocolParserStream; struct Banner1; enum App_Event { APP_CONNECTED, APP_RECV_TIMEOUT, APP_RECV_PAYLOAD, APP_SENDING, APP_SEND_SENT, APP_CLOSE /*FIN received */ }; /** * This is the interface between the underlying custom TCP/IP stack and * the rest of masscan. SCRIPTING will eventually go in here. */ unsigned application_event( struct stack_handle_t *socket, unsigned state, enum App_Event event, const struct ProtocolParserStream *stream, struct Banner1 *banner1, const void *payload, size_t payload_length ); void banner_set_sslhello(struct stack_handle_t *socket, bool is_true); void banner_set_small_window(struct stack_handle_t *socket, bool is_true); bool banner_is_heartbleed(const struct stack_handle_t *socket); void banner_flush(struct stack_handle_t *socket); size_t banner_parse( struct stack_handle_t *socket, const unsigned char *payload, size_t payload_length ); #endif
1,207
C
.c
41
24.073171
71
0.679066
robertdavidgraham/masscan
23,250
3,042
399
AGPL-3.0
9/7/2024, 9:40:14 AM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
5,438
main-listscan.c
robertdavidgraham_masscan/src/main-listscan.c
#include "masscan.h" #include "util-logger.h" #include "crypto-blackrock.h" void main_listscan(struct Masscan *masscan) { uint64_t i; uint64_t range; uint64_t start; uint64_t end; struct BlackRock blackrock; unsigned increment = masscan->shard.of; uint64_t seed = masscan->seed; /* If called with no ports, then create a pseudo-port needed * for the internal algorithm. */ if (!massip_has_target_ports(&masscan->targets)) rangelist_add_range(&masscan->targets.ports, 80, 80); massip_optimize(&masscan->targets); /* The "range" is the total number of IP/port combinations that * the scan can produce */ range = massip_range(&masscan->targets).lo; infinite: blackrock_init(&blackrock, range, seed, masscan->blackrock_rounds); start = masscan->resume.index + (masscan->shard.one-1); end = range; if (masscan->resume.count && end > start + masscan->resume.count) end = start + masscan->resume.count; end += (uint64_t)(masscan->retries * masscan->max_rate); for (i=start; i<end; ) { uint64_t xXx; unsigned port; ipaddress addr; xXx = blackrock_shuffle(&blackrock, i); massip_pick(&masscan->targets, xXx, &addr, &port); if (masscan->is_test_csv) { /* [KLUDGE] [TEST] * For testing randomness output, prints last two bytes of * IP address as CSV format for import into spreadsheet */ printf("%u,%u\n",(addr.ipv4>>8)&0xFF, (addr.ipv4>>0)&0xFF); } else if (masscan->targets.count_ports == 1) { ipaddress_formatted_t fmt = ipaddress_fmt(addr); /* This is the normal case */ printf("%s\n", fmt.string); } else { ipaddress_formatted_t fmt = ipaddress_fmt(addr); if (addr.version == 6) printf("[%s]:%u\n", fmt.string, port); else printf("%s:%u\n", fmt.string, port); } i += increment; /* <------ increment by 1 normally, more with shards/NICs */ } if (masscan->is_infinite) { seed++; goto infinite; } }
2,186
C
.c
58
29.87931
84
0.596391
robertdavidgraham/masscan
23,250
3,042
399
AGPL-3.0
9/7/2024, 9:40:14 AM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
5,439
syn-cookie.h
robertdavidgraham_masscan/src/syn-cookie.h
#ifndef SYN_COOKIE_H #define SYN_COOKIE_H #include <stdint.h> #include "massip-addr.h" /** * Create a hash of the src/dst IP/port combination. This allows us to match * incoming responses with their original requests */ uint64_t syn_cookie_ipv4( unsigned ip_dst, unsigned port_dst, unsigned ip_src, unsigned port_src, uint64_t entropy); uint64_t syn_cookie( ipaddress ip_dst, unsigned port_dst, ipaddress ip_src, unsigned port_src, uint64_t entropy); uint64_t syn_cookie_ipv6( ipv6address ip_dst, unsigned port_dst, ipv6address ip_src, unsigned port_src, uint64_t entropy); /** * Called on startup to set a secret key */ uint64_t get_entropy(void); #endif
740
C
.c
25
25.24
76
0.69774
robertdavidgraham/masscan
23,250
3,042
399
AGPL-3.0
9/7/2024, 9:40:14 AM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
5,444
main-initadapter.c
robertdavidgraham_masscan/src/main-initadapter.c
#include "masscan.h" #include "util-logger.h" #include "rawsock.h" #include "rawsock-adapter.h" #include "stack-arpv4.h" #include "stack-ndpv6.h" #include "stub-pcap-dlt.h" /*************************************************************************** * Initialize the network adapter. * * This requires finding things like our IP address, MAC address, and router * MAC address. The user could configure these things manually instead. * * Note that we don't update the "static" configuration with the discovered * values, but instead return them as the "running" configuration. That's * so if we pause and resume a scan, auto discovered values don't get saved * in the configuration file. ***************************************************************************/ int masscan_initialize_adapter( struct Masscan *masscan, unsigned index, macaddress_t *source_mac, macaddress_t *router_mac_ipv4, macaddress_t *router_mac_ipv6 ) { char *ifname; char ifname2[256]; unsigned adapter_ip = 0; unsigned is_usable_ipv4 = !massip_has_ipv4_targets(&masscan->targets); /* I don't understand this line, seems opposite */ unsigned is_usable_ipv6 = !massip_has_ipv6_targets(&masscan->targets); /* I don't understand this line, seems opposite */ ipaddress_formatted_t fmt; /* * ADAPTER/NETWORK-INTERFACE * * If no network interface was configured, we need to go hunt down * the best Interface to use. We do this by choosing the first * interface with a "default route" (aka. "gateway") defined */ if (masscan->nic[index].ifname[0]) ifname = masscan->nic[index].ifname; else { /* no adapter specified, so find a default one */ int err; ifname2[0] = '\0'; err = rawsock_get_default_interface(ifname2, sizeof(ifname2)); if (err || ifname2[0] == '\0') { LOG(0, "[-] FAIL: could not determine default interface\n"); LOG(0, " [hint] try \"--interface ethX\"\n"); return -1; } ifname = ifname2; } LOG(1, "[+] interface = %s\n", ifname); /* * START ADAPTER * * Once we've figured out which adapter to use, we now need to * turn it on. */ masscan->nic[index].adapter = rawsock_init_adapter( ifname, masscan->is_pfring, masscan->is_sendq, masscan->nmap.packet_trace, masscan->is_offline, (void*)masscan->bpf_filter, masscan->nic[index].is_vlan, masscan->nic[index].vlan_id); if (masscan->nic[index].adapter == 0) { LOG(0, "[-] if:%s:init: failed\n", ifname); return -1; } masscan->nic[index].link_type = masscan->nic[index].adapter->link_type; LOG(1, "[+] interface-type = %u\n", masscan->nic[index].link_type); rawsock_ignore_transmits(masscan->nic[index].adapter, ifname); /* * MAC ADDRESS * * This is the address we send packets from. It actually doesn't really * matter what this address is, but to be a "responsible" citizen we * try to use the hardware address in the network card. */ if (masscan->nic[index].link_type == PCAP_DLT_NULL) { LOG(1, "[+] source-mac = %s\n", "none"); } else if (masscan->nic[index].link_type == PCAP_DLT_RAW) { LOG(1, "[+] source-mac = %s\n", "none"); } else { *source_mac = masscan->nic[index].source_mac; if (masscan->nic[index].my_mac_count == 0) { if (macaddress_is_zero(*source_mac)) { rawsock_get_adapter_mac(ifname, source_mac->addr); } /* If still zero, then print error message */ if (macaddress_is_zero(*source_mac)) { fprintf(stderr, "[-] FAIL: failed to detect MAC address of interface:" " \"%s\"\n", ifname); fprintf(stderr, " [hint] try something like " "\"--source-mac 00-11-22-33-44-55\"\n"); return -1; } } fmt = macaddress_fmt(*source_mac); LOG(1, "[+] source-mac = %s\n", fmt.string); } /* * IPv4 ADDRESS * * We need to figure out that IP address to send packets from. This * is done by querying the adapter (or configured by user). If the * adapter doesn't have one, then the user must configure one. */ if (massip_has_ipv4_targets(&masscan->targets)) { adapter_ip = masscan->nic[index].src.ipv4.first; if (adapter_ip == 0) { adapter_ip = rawsock_get_adapter_ip(ifname); masscan->nic[index].src.ipv4.first = adapter_ip; masscan->nic[index].src.ipv4.last = adapter_ip; masscan->nic[index].src.ipv4.range = 1; } if (adapter_ip == 0) { /* We appear to have IPv4 targets, yet we cannot find an adapter * to use for those targets. We are having trouble querying the * operating system stack. */ LOG(0, "[-] FAIL: failed to detect IP of interface \"%s\"\n", ifname); LOG(0, " [hint] did you spell the name correctly?\n"); LOG(0, " [hint] if it has no IP address, manually set with something like " "\"--source-ip 198.51.100.17\"\n"); if (massip_has_ipv4_targets(&masscan->targets)) { return -1; } } fmt = ipv4address_fmt(adapter_ip); LOG(1, "[+] source-ip = %s\n", fmt.string); if (adapter_ip != 0) is_usable_ipv4 = 1; /* * ROUTER MAC ADDRESS * * NOTE: this is one of the least understood aspects of the code. We must * send packets to the local router, which means the MAC address (not * IP address) of the router. * * Note: in order to ARP the router, we need to first enable the libpcap * code above. */ *router_mac_ipv4 = masscan->nic[index].router_mac_ipv4; if (masscan->is_offline) { /* If we are doing offline benchmarking/testing, then create * a fake MAC address fro the router */ memcpy(router_mac_ipv4->addr, "\x66\x55\x44\x33\x22\x11", 6); } else if (masscan->nic[index].link_type == PCAP_DLT_NULL) { /* If it's a VPN tunnel, then there is no Ethernet MAC address */ LOG(1, "[+] router-mac-ipv4 = %s\n", "implicit"); } else if (masscan->nic[index].link_type == PCAP_DLT_RAW) { /* If it's a VPN tunnel, then there is no Ethernet MAC address */ LOG(1, "[+] router-mac-ipv4 = %s\n", "implicit"); } else if (macaddress_is_zero(*router_mac_ipv4)) { ipv4address_t router_ipv4 = masscan->nic[index].router_ip; int err = 0; LOG(2, "[+] if(%s): looking for default gateway\n", ifname); if (router_ipv4 == 0) err = rawsock_get_default_gateway(ifname, &router_ipv4); if (err == 0) { fmt = ipv4address_fmt(router_ipv4); LOG(1, "[+] router-ip = %s\n", fmt.string); LOG(2, "[+] if(%s):arp: resolving IPv4 address\n", ifname); stack_arp_resolve( masscan->nic[index].adapter, adapter_ip, *source_mac, router_ipv4, router_mac_ipv4); } fmt = macaddress_fmt(*router_mac_ipv4); LOG(1, "[+] router-mac-ipv4 = %s\n", fmt.string); if (macaddress_is_zero(*router_mac_ipv4)) { fmt = ipv4address_fmt(masscan->nic[index].router_ip); LOG(0, "[-] FAIL: ARP timed-out resolving MAC address for router %s: \"%s\"\n", ifname, fmt.string); LOG(0, " [hint] try \"--router ip 192.0.2.1\" to specify different router\n"); LOG(0, " [hint] try \"--router-mac 66-55-44-33-22-11\" instead to bypass ARP\n"); LOG(0, " [hint] try \"--interface eth0\" to change interface\n"); return -1; } } } /* * IPv6 ADDRESS * * We need to figure out that IPv6 address to send packets from. This * is done by querying the adapter (or configured by user). If the * adapter doesn't have one, then the user must configure one. */ if (massip_has_ipv6_targets(&masscan->targets)) { ipv6address adapter_ipv6 = masscan->nic[index].src.ipv6.first; if (ipv6address_is_zero(adapter_ipv6)) { adapter_ipv6 = rawsock_get_adapter_ipv6(ifname); masscan->nic[index].src.ipv6.first = adapter_ipv6; masscan->nic[index].src.ipv6.last = adapter_ipv6; masscan->nic[index].src.ipv6.range = 1; } if (ipv6address_is_zero(adapter_ipv6)) { fprintf(stderr, "[-] FAIL: failed to detect IPv6 address of interface \"%s\"\n", ifname); fprintf(stderr, " [hint] did you spell the name correctly?\n"); fprintf(stderr, " [hint] if it has no IP address, manually set with something like " "\"--source-ip 2001:3b8::1234\"\n"); return -1; } fmt = ipv6address_fmt(adapter_ipv6); LOG(1, "[+] source-ip = [%s]\n", fmt.string); is_usable_ipv6 = 1; /* * ROUTER MAC ADDRESS */ *router_mac_ipv6 = masscan->nic[index].router_mac_ipv6; if (masscan->is_offline) { memcpy(router_mac_ipv6->addr, "\x66\x55\x44\x33\x22\x11", 6); } if (macaddress_is_zero(*router_mac_ipv6)) { /* [synchronous] * Wait for router neighbor notification. This may take * some time */ stack_ndpv6_resolve( masscan->nic[index].adapter, adapter_ipv6, *source_mac, router_mac_ipv6); } fmt = macaddress_fmt(*router_mac_ipv6); LOG(1, "[+] router-mac-ipv6 = %s\n", fmt.string); if (macaddress_is_zero(*router_mac_ipv6)) { fmt = ipv4address_fmt(masscan->nic[index].router_ip); LOG(0, "[-] FAIL: NDP timed-out resolving MAC address for router %s: \"%s\"\n", ifname, fmt.string); LOG(0, " [hint] try \"--router-mac-ipv6 66-55-44-33-22-11\" instead to bypass ARP\n"); LOG(0, " [hint] try \"--interface eth0\" to change interface\n"); return -1; } } masscan->nic[index].is_usable = (is_usable_ipv4 & is_usable_ipv6); LOG(2, "[+] if(%s): initialization done.\n", ifname); return 0; }
11,136
C
.c
244
34.27459
125
0.537898
robertdavidgraham/masscan
23,250
3,042
399
AGPL-3.0
9/7/2024, 9:40:14 AM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
5,450
rawsock-getip6.c
robertdavidgraham_masscan/src/rawsock-getip6.c
/* retrieve IPv4 address of the named network interface/adapter like "eth0" This works on: - Windows - Linux - Apple - FreeBSD I think it'll work the same on any BSD system. */ #include "rawsock.h" #include "util-safefunc.h" #include "massip-parse.h" /***************************************************************************** *****************************************************************************/ #if defined(__linux__) #define _GNU_SOURCE #include <arpa/inet.h> #include <sys/socket.h> #include <netdb.h> #include <ifaddrs.h> #include <stdio.h> #include <stdlib.h> #include <unistd.h> #include <linux/if_link.h> #include <unistd.h> #include <sys/types.h> #include <sys/socket.h> #include <sys/ioctl.h> #include <netinet/in.h> #include <net/if.h> #include <arpa/inet.h> #include <ifaddrs.h> ipv6address rawsock_get_adapter_ipv6(const char *ifname) { struct ifaddrs *list = NULL; struct ifaddrs *ifa; int err; ipv6address result = {0,0}; /* Fetch the list of addresses */ err = getifaddrs(&list); if (err == -1) { fprintf(stderr, "[-] getifaddrs(): %s\n", strerror(errno)); return result; } for (ifa = list; ifa != NULL; ifa = ifa->ifa_next) { ipv6address addr; if (ifa->ifa_addr == NULL) continue; if (ifa->ifa_name == NULL) continue; if (strcmp(ifname, ifa->ifa_name) != 0) continue; if (ifa->ifa_addr->sa_family != AF_INET6) continue; addr = ipv6address_from_bytes((const unsigned char *)&((struct sockaddr_in6 *)ifa->ifa_addr)->sin6_addr); if (addr.hi>>56ULL >= 0xFC) continue; if (addr.hi>>32ULL == 0x20010db8) continue; result = addr; break; } freeifaddrs(list); return result; } /***************************************************************************** *****************************************************************************/ #elif defined(WIN32) /* From: * https://stackoverflow.com/questions/10972794/undefined-reference-to-getadaptersaddresses20-but-i-included-liphlpapi */ #if !defined(_WIN32_WINNT) || _WIN32_WINNT < 0x501 #undef _WIN32_WINNT #define _WIN32_WINNT 0x501 #endif #define WIN32_LEAN_AND_MEAN #include <winsock2.h> #include <WS2tcpip.h> #include <iphlpapi.h> #ifdef _MSC_VER #pragma comment(lib, "IPHLPAPI.lib") #endif ipv6address rawsock_get_adapter_ipv6(const char *ifname) { ULONG err; ipv6address result = {0,0}; IP_ADAPTER_ADDRESSES *adapters = NULL; IP_ADAPTER_ADDRESSES *adapter; IP_ADAPTER_UNICAST_ADDRESS *addr; ULONG sizeof_addrs = 0; ifname = rawsock_win_name(ifname); again: err = GetAdaptersAddresses( AF_INET6, /* Get IPv6 addresses only */ 0, 0, adapters, &sizeof_addrs); if (err == ERROR_BUFFER_OVERFLOW) { free(adapters); adapters = malloc(sizeof_addrs); if (adapters == NULL) { fprintf(stderr, "GetAdaptersAddresses():malloc(): failed: out of memory\n"); return result; } goto again; } if (err != NO_ERROR) { fprintf(stderr, "GetAdaptersAddresses(): failed: %u\n", (unsigned)err); return result; } /* * loop through all adapters looking for ours */ for (adapter = adapters; adapter != NULL; adapter = adapter->Next) { if (rawsock_is_adapter_names_equal(adapter->AdapterName, ifname)) break; } /* * If our adapter isn't found, print an error. */ if (adapters == NULL) { fprintf(stderr, "GetAdaptersInfo: adapter not found: %s\n", ifname); goto end; } /* * Search through the list of returned addresses looking for the first * that matches an IPv6 address. */ for (addr = adapter->FirstUnicastAddress; addr; addr = addr->Next) { struct sockaddr_in6 *sa = (struct sockaddr_in6 *)addr->Address.lpSockaddr; //char buf[64]; ipv6address ipv6; /* Ignore any address that isn't IPv6 */ if (sa->sin6_family != AF_INET6) continue; /* Ignore transient cluster addresses */ if (addr->Flags == IP_ADAPTER_ADDRESS_TRANSIENT) continue; /* Don't use operating-system function for this, because they aren't * really portable or safe */ ipv6 = ipv6address_from_bytes((const unsigned char *)&sa->sin6_addr); if (addr->PrefixOrigin == IpPrefixOriginWellKnown) { /* This value applies to an IPv6 link-local address or an IPv6 loopback address */ continue; } if (addr->PrefixOrigin == IpPrefixOriginRouterAdvertisement && addr->SuffixOrigin == IpSuffixOriginRandom) { /* This is a temporary IPv6 address * See: http://technet.microsoft.com/en-us/ff568768(v=vs.60).aspx */ continue; } if (ipv6.hi>>56ULL >= 0xFC) continue; if (ipv6.hi>>32ULL == 0x20010db8) continue; result = ipv6; } end: free(adapters); return result; } /***************************************************************************** *****************************************************************************/ #elif defined(__APPLE__) || defined(__FreeBSD__) || defined(__NetBSD__) || 1 #include <sys/types.h> #include <sys/socket.h> #include <ifaddrs.h> #include <stdio.h> #include <arpa/inet.h> #include <netinet/in.h> #ifdef AF_LINK # include <net/if_dl.h> #endif #ifdef AF_PACKET # include <netpacket/packet.h> #endif ipv6address rawsock_get_adapter_ipv6(const char *ifname) { struct ifaddrs *list = NULL; struct ifaddrs *ifa; int err; ipv6address result = {0,0}; /* Fetch the list of addresses */ err = getifaddrs(&list); if (err == -1) { fprintf(stderr, "[-] getifaddrs(): %s\n", strerror(errno)); return result; } for (ifa = list; ifa != NULL; ifa = ifa->ifa_next) { ipv6address addr; if (ifa->ifa_addr == NULL) continue; if (ifa->ifa_name == NULL) continue; if (strcmp(ifname, ifa->ifa_name) != 0) continue; if (ifa->ifa_addr->sa_family != AF_INET6) continue; addr = ipv6address_from_bytes((const unsigned char *)&((struct sockaddr_in6 *)ifa->ifa_addr)->sin6_addr); if (addr.hi>>56ULL >= 0xFC) continue; if (addr.hi>>32ULL == 0x20010db8) continue; result = addr; break; } freeifaddrs(list); return result; } #endif
6,790
C
.c
214
25.345794
118
0.560467
robertdavidgraham/masscan
23,250
3,042
399
AGPL-3.0
9/7/2024, 9:40:14 AM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
5,451
stack-tcp-core.c
robertdavidgraham_masscan/src/stack-tcp-core.c
/* * This is the core TCP layer in the stack. It's notified of incoming * IP datagrams containing TCP protocols. This is where the TCP state * diagram is handled. * * * +---------+ ---------\ active OPEN * | CLOSED | \ ----------- * +---------+<---------\ \ create TCB * | ^ \ \ snd SYN * passive OPEN | | CLOSE \ \ * ------------ | | ---------- \ \ * create TCB | | delete TCB \ \ * V | \ \ * +---------+ CLOSE | \ * | LISTEN | ---------- | | * +---------+ delete TCB | | * rcv SYN | | SEND | | * ----------- | | ------- | V * +---------+ snd SYN,ACK / \ snd SYN +---------+ * | |<----------------- ------------------>| | * | SYN | rcv SYN | SYN | * | RCVD |<-----------------------------------------------| SENT | * | | snd ACK | | * | |------------------ -------------------| | * +---------+ rcv ACK of SYN \ / rcv SYN,ACK +---------+ * | -------------- | | ----------- * | x | | snd ACK * | V V * | CLOSE +---------+ * | ------- | ESTAB | * | snd FIN +---------+ * | CLOSE | | rcv FIN * V ------- | | ------- * +---------+ snd FIN / \ snd ACK +---------+ * | FIN |<----------------- ------------------>| CLOSE | * | WAIT-1 |------------------ | WAIT | * +---------+ rcv FIN \ +---------+ * | rcv ACK of FIN ------- | CLOSE | * | -------------- snd ACK | ------- | * V x V snd FIN V * +---------+ +---------+ +---------+ * |FINWAIT-2| | CLOSING | | LAST-ACK| * +---------+ +---------+ +---------+ * | rcv ACK of FIN | rcv ACK of FIN | * | rcv FIN -------------- | Timeout=2MSL -------------- | * | ------- x V ------------ x V * \ snd ACK +---------+delete TCB +---------+ * ------------------------>|TIME WAIT|------------------>| CLOSED | * +---------+ +---------+ * */ #include "stack-tcp-core.h" #include "stack-tcp-api.h" #include "stack-tcp-app.h" #include <assert.h> #include <ctype.h> #include <stdio.h> #include <stdint.h> #include <stdlib.h> #include <string.h> #include <time.h> #include <stddef.h> #include <stdarg.h> #include "syn-cookie.h" #include "event-timeout.h" /* for tracking future events */ #include "rawsock.h" #include "util-logger.h" #include "templ-pkt.h" #include "pixie-timer.h" #include "stack-queue.h" #include "proto-banner1.h" #include "proto-ssl.h" #include "proto-http.h" #include "proto-smb.h" #include "proto-versioning.h" #include "output.h" #include "util-safefunc.h" #include "main-globals.h" #include "crypto-base64.h" #include "util-malloc.h" #include "util-errormsg.h" #include "scripting.h" #ifdef _MSC_VER #pragma warning(disable:4204) #define snprintf _snprintf #pragma warning(disable:4996) #endif struct TCP_Segment { unsigned seqno; unsigned char *buf; size_t length; enum TCP__flags flags; bool is_fin; /* was fin sent */ struct TCP_Segment *next; }; /*************************************************************************** * A "TCP control block" is what most operating-systems/network-stack * calls the structure that corresponds to a TCP connection. It contains * things like the IP addresses, port numbers, sequence numbers, timers, * and other things. ***************************************************************************/ struct TCP_Control_Block { ipaddress ip_me; ipaddress ip_them; unsigned short port_me; unsigned short port_them; uint32_t seqno_me; /* next seqno I will use for transmit */ uint32_t seqno_them; /* the next seqno I expect to receive */ uint32_t ackno_me; uint32_t ackno_them; uint32_t seqno_me_first; uint32_t seqno_them_first; struct TCP_Control_Block *next; struct TimeoutEntry timeout[1]; unsigned char ttl; unsigned char syns_sent; /* reconnect */ unsigned short mss; /* maximum segment size 1460 */ unsigned tcpstate:4; unsigned is_ipv6:1; unsigned is_small_window:1; /* send with smaller window */ unsigned is_their_fin:1; /** Set to true when the TCB is in-use/allocated, set to zero * when it's about to be deleted soon */ unsigned is_active:1; /* If the payload we've sent was dynamically allocated with * malloc() from the heap, in which case we'll have to free() * it. (Most payloads are static memory) */ unsigned is_payload_dynamic:1; unsigned app_state; struct TCP_Segment *segments; /* unsigned short payload_length; const unsigned char *payload; */ time_t when_created; /* * If Running a script, the thread object */ struct ScriptingThread *scripting_thread; const struct ProtocolParserStream *stream; struct BannerOutput banout; struct StreamState banner1_state; unsigned packet_number; }; struct TCP_ConnectionTable { struct TCP_Control_Block **entries; struct TCP_Control_Block *freed_list; unsigned count; unsigned mask; unsigned timeout_connection; unsigned timeout_hello; uint64_t active_count; uint64_t entropy; struct Timeouts *timeouts; struct TemplatePacket *pkt_template; struct stack_t *stack; struct Banner1 *banner1; OUTPUT_REPORT_BANNER report_banner; struct Output *out; struct ScriptingVM *scripting_vm; /** This is for creating follow-up connections based on the first * connection. Given an existing IP/port, it returns a different * one for the new conenction. */ struct { const void *data; void *(*cb)(const void *in_src, const ipaddress ip, unsigned port, ipaddress *next_ip, unsigned *next_port); } next_ip_port; }; enum { STATE_SYN_SENT=0, /* must be zero */ //STATE_SYN_RECEIVED, STATE_ESTABLISHED_SEND, /* our own special state, can only send */ STATE_ESTABLISHED_RECV, /* our own special state, can only receive */ STATE_CLOSE_WAIT, STATE_LAST_ACK, STATE_FIN_WAIT1_SEND, STATE_FIN_WAIT1_RECV, STATE_FIN_WAIT2, STATE_CLOSING, STATE_TIME_WAIT, }; /*************************************************************************** * DEBUG: when printing debug messages (-d option), this prints a string * for the given state. ***************************************************************************/ static const char * state_to_string(int state) { static char buf[64]; switch (state) { //STATE_SYN_RECEIVED, case STATE_CLOSE_WAIT: return "CLOSE-WAIT"; case STATE_LAST_ACK: return "LAST-ACK"; case STATE_FIN_WAIT1_SEND: return "FIN-WAIT-1-SEND"; case STATE_FIN_WAIT1_RECV: return "FIN-WAIT-1-RECV"; case STATE_FIN_WAIT2: return "FIN-WAIT-2"; case STATE_CLOSING: return "CLOSING"; case STATE_TIME_WAIT: return "TIME-WAIT"; case STATE_SYN_SENT: return "SYN_SENT"; case STATE_ESTABLISHED_SEND:return "ESTABLISHED_SEND"; case STATE_ESTABLISHED_RECV:return "ESTABLISHED_RECV"; default: snprintf(buf, sizeof(buf), "%d", state); return buf; } } static void vLOGtcb(const struct TCP_Control_Block *tcb, int dir, const char *fmt, va_list marker) { char sz[256]; ipaddress_formatted_t fmt1 = ipaddress_fmt(tcb->ip_them); snprintf(sz, sizeof(sz), "[%s:%u %4u,%4u] %s:%5u [%4u,%4u] {%s} ", fmt1.string, tcb->port_them, tcb->seqno_them - tcb->seqno_them_first, tcb->ackno_me - tcb->seqno_them_first, (dir > 0) ? "-->" : "<--", tcb->port_me, tcb->seqno_me - tcb->seqno_me_first, tcb->ackno_them - tcb->seqno_me_first, state_to_string(tcb->tcpstate) ); if (dir == 2) { char *brace = strchr(sz, '{'); memset(sz, ' ', brace-sz); } fprintf(stderr, "%s", sz); vfprintf(stderr, fmt, marker); fflush(stderr); } int is_tcp_debug = 0; static void LOGtcb(const struct TCP_Control_Block *tcb, int dir, const char *fmt, ...) { va_list marker; if (!is_tcp_debug) return; va_start(marker, fmt); vLOGtcb(tcb, dir, fmt, marker); va_end(marker); } /*************************************************************************** * Process all events, up to the current time, that need timing out. ***************************************************************************/ void tcpcon_timeouts(struct TCP_ConnectionTable *tcpcon, unsigned secs, unsigned usecs) { uint64_t timestamp = TICKS_FROM_TV(secs, usecs); for (;;) { struct TCP_Control_Block *tcb; enum TCB_result x; /* * Get the next event that is older than the current time */ tcb = (struct TCP_Control_Block *)timeouts_remove(tcpcon->timeouts, timestamp); /* * If everything up to the current time has already been processed, * then exit this loop */ if (tcb == NULL) break; /* * Process this timeout */ x = stack_incoming_tcp(tcpcon, tcb, TCP_WHAT_TIMEOUT, 0, 0, secs, usecs, tcb->seqno_them, tcb->ackno_them); /* If the TCB hasn't been destroyed, then we need to make sure * there is a timeout associated with it. KLUDGE: here is the problem: * there must ALWAYS be a 'timeout' associated with a TCB, otherwise, * we'll lose track of it and leak memory. In theory, this should be * automatically handled elsewhere, but I have bugs, and it's not, * so I put some code here as a catch-all: if the TCB hasn't been * deleted, but hasn't been inserted back into the timeout system, * then insert it here. */ if (x != TCB__destroyed && timeout_is_unlinked(tcb->timeout)) { timeouts_add( tcpcon->timeouts, tcb->timeout, offsetof(struct TCP_Control_Block, timeout), TICKS_FROM_TV(secs+2, usecs)); } } } /*************************************************************************** ***************************************************************************/ static int name_equals(const char *lhs, const char *rhs) { for (;;) { while (*lhs == '-' || *lhs == '.' || *lhs == '_') lhs++; while (*rhs == '-' || *rhs == '.' || *rhs == '_') rhs++; if (*lhs == '\0' && *rhs == '[') return 1; /*arrays*/ if (*rhs == '\0' && *lhs == '[') return 1; /*arrays*/ if (tolower(*lhs & 0xFF) != tolower(*rhs & 0xFF)) return 0; if (*lhs == '\0') return 1; lhs++; rhs++; } } /*************************************************************************** * When setting parameters, this will parse integers from the config * parameter strings. ***************************************************************************/ static uint64_t parseInt(const void *vstr, size_t length) { const char *str = (const char *)vstr; uint64_t result = 0; size_t i; for (i=0; i<length; i++) { result = result * 10 + (str[i] - '0'); } return result; } /*************************************************************************** * Called at startup, when processing command-line options, to set * an HTTP field. ***************************************************************************/ void tcpcon_set_http_header(struct TCP_ConnectionTable *tcpcon, const char *name, size_t value_length, const void *value, enum http_field_t what) { UNUSEDPARM(tcpcon); banner_http.hello_length = http_change_field( (unsigned char**)&banner_http.hello, banner_http.hello_length, name, (const unsigned char *)value, value_length, what); } /*************************************************************************** * Called at startup, when processing command-line options, to set * parameters specific to TCP processing. ***************************************************************************/ void tcpcon_set_parameter(struct TCP_ConnectionTable *tcpcon, const char *name, size_t value_length, const void *value) { struct Banner1 *banner1 = tcpcon->banner1; if (name_equals(name, "http-payload")) { char lenstr[64]; snprintf(lenstr, sizeof(lenstr), "%u", (unsigned)value_length); banner_http.hello_length = http_change_requestline( (unsigned char**)&banner_http.hello, banner_http.hello_length, (const unsigned char *)value, value_length, 3); /* payload*/ banner_http.hello_length = http_change_field( (unsigned char**)&banner_http.hello, banner_http.hello_length, "Content-Length:", (const unsigned char *)lenstr, strlen(lenstr), http_field_replace); return; } /* * You can reset your user-agent here. Whenever I do a scan, I always * reset my user-agent. That's now you know it's not me scanning * you on the open Internet -- I would never use the default user-agent * string built into masscan */ if (name_equals(name, "http-user-agent")) { banner_http.hello_length = http_change_field( (unsigned char**)&banner_http.hello, banner_http.hello_length, "User-Agent:", (const unsigned char *)value, value_length, http_field_replace); return; } if (name_equals(name, "http-host")) { banner_http.hello_length = http_change_field( (unsigned char**)&banner_http.hello, banner_http.hello_length, "Host:", (const unsigned char *)value, value_length, http_field_replace); return; } /** * Changes the URL */ if (name_equals(name, "http-method")) { banner_http.hello_length = http_change_requestline( (unsigned char**)&banner_http.hello, banner_http.hello_length, (const unsigned char *)value, value_length, 0); /* method*/ return; } if (name_equals(name, "http-url")) { banner_http.hello_length = http_change_requestline( (unsigned char**)&banner_http.hello, banner_http.hello_length, (const unsigned char *)value, value_length, 1); /* url */ return; } if (name_equals(name, "http-version")) { banner_http.hello_length = http_change_requestline( (unsigned char**)&banner_http.hello, banner_http.hello_length, (const unsigned char *)value, value_length, 2); /* version */ return; } if (name_equals(name, "timeout") || name_equals(name, "connection-timeout")) { uint64_t n = parseInt(value, value_length); tcpcon->timeout_connection = (unsigned)n; LOG(1, "TCP connection-timeout = %u\n", tcpcon->timeout_connection); return; } if (name_equals(name, "hello-timeout")) { uint64_t n = parseInt(value, value_length); tcpcon->timeout_hello = (unsigned)n; LOG(1, "TCP hello-timeout = \"%.*s\"\n", (int)value_length, (const char *)value); LOG(1, "TCP hello-timeout = %u\n", (unsigned)tcpcon->timeout_hello); return; } /* * Force SSL processing on all ports */ if (name_equals(name, "hello") && name_equals(value, "ssl")) { unsigned i; LOG(2, "HELLO: setting SSL hello message\n"); for (i=0; i<65535; i++) { banner1->payloads.tcp[i] = &banner_ssl; } return; } /* * Force HTTP processing on all ports */ if (name_equals(name, "hello") && name_equals(value, "http")) { unsigned i; LOG(2, "HELLO: setting HTTP hello message\n"); for (i=0; i<65535; i++) { banner1->payloads.tcp[i] = &banner_http; } return; } /* * Downgrade SMB hello from v1/v2 to use only v1 */ if (name_equals(name, "hello") && name_equals(value, "smbv1")) { smb_set_hello_v1(&banner_smb1); return; } /* * 2014-04-08: scan for Neel Mehta's "heartbleed" bug */ if (name_equals(name, "heartbleed")) { unsigned i; /* Change the hello message to including negotiating the use of * the "heartbeat" extension */ banner_ssl.hello = ssl_hello(ssl_hello_heartbeat_template); banner_ssl.hello_length = ssl_hello_size(banner_ssl.hello); tcpcon->banner1->is_heartbleed = 1; for (i=0; i<65535; i++) { banner1->payloads.tcp[i] = &banner_ssl; } return; } if (name_equals(name, "ticketbleed")) { unsigned i; /* Change the hello message to including negotiating the use of * the "heartbeat" extension */ banner_ssl.hello = ssl_hello(ssl_hello_ticketbleed_template); banner_ssl.hello_length = ssl_hello_size(banner_ssl.hello); tcpcon->banner1->is_ticketbleed = 1; for (i=0; i<65535; i++) { banner1->payloads.tcp[i] = &banner_ssl; } return; } /* * 2014-10-16: scan for SSLv3 servers (POODLE) */ if (name_equals(name, "poodle") || name_equals(name, "sslv3")) { unsigned i; void *px; /* Change the hello message to including negotiating the use of * the "heartbeat" extension */ px = ssl_hello(ssl_hello_sslv3_template); banner_ssl.hello = ssl_add_cipherspec(px, 0x5600, 1); banner_ssl.hello_length = ssl_hello_size(banner_ssl.hello); tcpcon->banner1->is_poodle_sslv3 = 1; for (i=0; i<65535; i++) { banner1->payloads.tcp[i] = &banner_ssl; } return; } /* * You can reconfigure the "hello" message to be anything * you want. */ if (name_equals(name, "hello-string")) { struct ProtocolParserStream *x; const char *p = strchr(name, '['); unsigned port; if (p == NULL) { ERRMSG("tcpcon: parameter: expected array []: %s\n", name); return; } port = (unsigned)strtoul(p+1, 0, 0); x = CALLOC(1, sizeof(*x)); if (banner1->payloads.tcp[port]) memcpy(x, banner1->payloads.tcp[port], sizeof (*x)); x->name = "(allocated)"; x->hello = MALLOC(value_length); x->hello_length = base64_decode((char*)x->hello, value_length, value, value_length); banner1->payloads.tcp[port] = x; } } /*************************************************************************** ***************************************************************************/ void tcpcon_set_banner_flags(struct TCP_ConnectionTable *tcpcon, unsigned is_capture_cert, unsigned is_capture_servername, unsigned is_capture_html, unsigned is_capture_heartbleed, unsigned is_capture_ticketbleed) { tcpcon->banner1->is_capture_cert = is_capture_cert; tcpcon->banner1->is_capture_servername = is_capture_servername; tcpcon->banner1->is_capture_html = is_capture_html; tcpcon->banner1->is_capture_heartbleed = is_capture_heartbleed; tcpcon->banner1->is_capture_ticketbleed = is_capture_ticketbleed; } /*************************************************************************** ***************************************************************************/ void scripting_init_tcp(struct TCP_ConnectionTable *tcpcon, struct lua_State *L) { tcpcon->banner1->L = L; banner_scripting.init(tcpcon->banner1); } /*************************************************************************** * Called at startup, by a receive thread, to create a TCP connection * table. ***************************************************************************/ struct TCP_ConnectionTable * tcpcon_create_table( size_t entry_count, struct stack_t *stack, struct TemplatePacket *pkt_template, OUTPUT_REPORT_BANNER report_banner, struct Output *out, unsigned connection_timeout, uint64_t entropy ) { struct TCP_ConnectionTable *tcpcon; tcpcon = CALLOC(1, sizeof(*tcpcon)); tcpcon->timeout_connection = connection_timeout; if (tcpcon->timeout_connection == 0) tcpcon->timeout_connection = 30; /* half a minute before destroying tcb */ tcpcon->timeout_hello = 2; tcpcon->entropy = entropy; /* Find nearest power of 2 to the tcb count, but don't go * over the number 16-million */ { size_t new_entry_count; new_entry_count = 1; while (new_entry_count < entry_count) { new_entry_count *= 2; if (new_entry_count == 0) { new_entry_count = (1<<24); break; } } if (new_entry_count > (1<<24)) new_entry_count = (1<<24); if (new_entry_count < (1<<10)) new_entry_count = (1<<10); entry_count = new_entry_count; } /* Create the table. If we can't allocate enough memory, then shrink * the desired size of the table */ while (tcpcon->entries == 0) { tcpcon->entries = malloc(entry_count * sizeof(*tcpcon->entries)); if (tcpcon->entries == NULL) { entry_count >>= 1; } } memset(tcpcon->entries, 0, entry_count * sizeof(*tcpcon->entries)); /* fill in the table structure */ tcpcon->count = (unsigned)entry_count; tcpcon->mask = (unsigned)(entry_count-1); /* create an event/timeouts structure */ tcpcon->timeouts = timeouts_create(TICKS_FROM_SECS(time(0))); tcpcon->pkt_template = pkt_template; tcpcon->stack = stack; tcpcon->banner1 = banner1_create(); tcpcon->report_banner = report_banner; tcpcon->out = out; return tcpcon; } static int TCB_EQUALS(const struct TCP_Control_Block *lhs, const struct TCP_Control_Block *rhs) { if (lhs->port_me != rhs->port_me || lhs->port_them != rhs->port_them) return 0; if (lhs->ip_me.version != rhs->ip_me.version) return 0; if (lhs->ip_me.version == 6) { if (memcmp(&lhs->ip_me.ipv6, &rhs->ip_me.ipv6, sizeof(rhs->ip_me.ipv6)) != 0) return 0; if (memcmp(&lhs->ip_them.ipv6, &rhs->ip_them.ipv6, sizeof(rhs->ip_them.ipv6)) != 0) return 0; } else { if (lhs->ip_me.ipv4 != rhs->ip_me.ipv4) return 0; if (lhs->ip_them.ipv4 != rhs->ip_them.ipv4) return 0; } return 1; } /*************************************************************************** ***************************************************************************/ static void _tcb_change_state_to(struct TCP_Control_Block *tcb, unsigned new_state) { LOGtcb(tcb, 2, "to {%s}\n", state_to_string(new_state)); tcb->tcpstate = new_state; } /*************************************************************************** ***************************************************************************/ static unsigned tcb_hash( ipaddress ip_me, unsigned port_me, ipaddress ip_them, unsigned port_them, uint64_t entropy) { unsigned index; /* TCB hash table uses symmetric hash, so incoming/outgoing packets * get the same hash. */ if (ip_me.version == 6) { ipv6address ipv6 = ip_me.ipv6; ipv6.hi ^= ip_them.ipv6.hi; ipv6.lo ^= ip_them.ipv6.lo; index = (unsigned)syn_cookie_ipv6( ipv6, port_me ^ port_them, ipv6, port_me ^ port_them, entropy); } else { index = (unsigned)syn_cookie_ipv4( ip_me.ipv4 ^ ip_them.ipv4, port_me ^ port_them, ip_me.ipv4 ^ ip_them.ipv4, port_me ^ port_them, entropy ); } return index; } enum DestroyReason { Reason_Timeout = 1, Reason_FIN = 2, Reason_RST = 3, Reason_Foo = 4, Reason_Shutdown = 5, Reason_StateDone = 6, }; /*************************************************************************** * Flush all the banners associated with this TCP connection. This always * called when TCB is destroyed. This may also be called earlier, such * as when a FIN is received. ***************************************************************************/ void banner_flush(struct stack_handle_t *socket) { struct TCP_ConnectionTable *tcpcon = socket->tcpcon; struct TCP_Control_Block *tcb = socket->tcb; struct BannerOutput *banout; /* Go through and print all the banners. Some protocols have * multiple banners. For example, web servers have both * HTTP and HTML banners, and SSL also has several * X.509 certificate banners */ for (banout = &tcb->banout; banout != NULL; banout = banout->next) { if (banout->length && banout->protocol) { tcpcon->report_banner( tcpcon->out, global_now, tcb->ip_them, 6, /*TCP protocol*/ tcb->port_them, banout->protocol & 0x0FFFFFFF, tcb->ttl, banout->banner, banout->length); } } /* * Free up all the banners. */ banout_release(&tcb->banout); } /*************************************************************************** * Destroy a TCP connection entry. We have to unlink both from the * TCB-table as well as the timeout-table. * Called from ***************************************************************************/ static void tcpcon_destroy_tcb( struct TCP_ConnectionTable *tcpcon, struct TCP_Control_Block *tcb, enum DestroyReason reason) { unsigned index; struct TCP_Control_Block **r_entry; UNUSEDPARM(reason); /* * The TCB doesn't point to it's location in the table. Therefore, we * have to do a lookup to find the head pointer in the table. */ index = tcb_hash( tcb->ip_me, tcb->port_me, tcb->ip_them, tcb->port_them, tcpcon->entropy); /* * At this point, we have the head of a linked list of TCBs. Now, * traverse that linked list until we find our TCB */ r_entry = &tcpcon->entries[index & tcpcon->mask]; while (*r_entry && *r_entry != tcb) r_entry = &(*r_entry)->next; if (*r_entry == NULL) { LOG(1, "tcb: double free\n"); return; } /* * Print out any banners associated with this TCP session. Most of the * time, there'll only be one. After printing them out, delete the * banners. */ { struct stack_handle_t socket = {tcpcon, tcb, 0, 0}; banner_flush(&socket); } LOGtcb(tcb, 2, "--DESTROYED--\n"); /* * If there are any queued segments to transmit, then free them */ while (tcb->segments) { struct TCP_Segment *seg; seg = tcb->segments; tcb->segments = seg->next; if (seg->flags == TCP__copy || seg->flags == TCP__adopt) { free(seg->buf); seg->buf = 0; } free(seg); } if (tcb->scripting_thread) ; //scripting_thread_close(tcb->scripting_thread); tcb->scripting_thread = 0; /* KLUDGE: this needs to be made elegant */ switch (tcb->banner1_state.app_proto) { case PROTO_SMB: banner_smb1.cleanup(&tcb->banner1_state); break; } /* * Unlink this from the timeout system. */ timeout_unlink(tcb->timeout); tcb->ip_them.ipv4 = (unsigned)~0; tcb->port_them = (unsigned short)~0; tcb->ip_me.ipv4 = (unsigned)~0; tcb->port_me = (unsigned short)~0; tcb->is_active = 0; (*r_entry) = tcb->next; tcb->next = tcpcon->freed_list; tcpcon->freed_list = tcb; tcpcon->active_count--; } /*************************************************************************** * Called at shutdown to free up all the memory used by the TCP * connection table. ***************************************************************************/ void tcpcon_destroy_table(struct TCP_ConnectionTable *tcpcon) { unsigned i; if (tcpcon == NULL) return; /* * Do a graceful destruction of all the entires. If they have banners, * they will be sent to the output */ for (i=0; i<=tcpcon->mask; i++) { while (tcpcon->entries[i]) tcpcon_destroy_tcb(tcpcon, tcpcon->entries[i], Reason_Shutdown); } /* * Now free the memory */ while (tcpcon->freed_list) { struct TCP_Control_Block *tcb = tcpcon->freed_list; tcpcon->freed_list = tcb->next; free(tcb); } banner1_destroy(tcpcon->banner1); free(tcpcon->entries); free(tcpcon); } /*************************************************************************** * * Called when we receive a "SYN-ACK" packet with the correct SYN-cookie. * ***************************************************************************/ struct TCP_Control_Block * tcpcon_create_tcb( struct TCP_ConnectionTable *tcpcon, ipaddress ip_me, ipaddress ip_them, unsigned port_me, unsigned port_them, unsigned seqno_me, unsigned seqno_them, unsigned ttl, const struct ProtocolParserStream *stream, unsigned secs, unsigned usecs) { unsigned index; struct TCP_Control_Block tmp; struct TCP_Control_Block *tcb; assert(ip_me.version != 0 && ip_them.version != 0); tmp.ip_me = ip_me; tmp.ip_them = ip_them; tmp.port_me = (unsigned short)port_me; tmp.port_them = (unsigned short)port_them; /* Lookup the location in the hash table where this tcb should be * placed */ index = tcb_hash(ip_me, port_me, ip_them, port_them, tcpcon->entropy); tcb = tcpcon->entries[index & tcpcon->mask]; while (tcb && !TCB_EQUALS(tcb, &tmp)) { tcb = tcb->next; } if (tcb != NULL) { /* If it already exists, just return the existing one */ return tcb; } /* Allocate a new TCB, using a pool */ if (tcpcon->freed_list) { tcb = tcpcon->freed_list; tcpcon->freed_list = tcb->next; } else { tcb = MALLOC(sizeof(*tcb)); } memset(tcb, 0, sizeof(*tcb)); /* Add it to this spot in the hash table */ tcb->next = tcpcon->entries[index & tcpcon->mask]; tcpcon->entries[index & tcpcon->mask] = tcb; /* * Initialize the entry */ tcb->ip_me = ip_me; tcb->ip_them = ip_them; tcb->port_me = (unsigned short)port_me; tcb->port_them = (unsigned short)port_them; tcb->seqno_them_first = seqno_them; tcb->seqno_me_first = seqno_me; tcb->seqno_me = seqno_me; tcb->seqno_them = seqno_them; tcb->ackno_me = seqno_them; tcb->ackno_them = seqno_me; tcb->when_created = global_now; tcb->ttl = (unsigned char)ttl; tcb->mss = 1400; /* Insert the TCB into the timeout. A TCB must always have a timeout * active. */ timeout_init(tcb->timeout); timeouts_add(tcpcon->timeouts, tcb->timeout, offsetof(struct TCP_Control_Block, timeout), TICKS_FROM_TV(secs+1,usecs) ); /* Get the protocol handler assigned to this port */ tcb->banner1_state.port = (unsigned short)port_them; if (stream == NULL) { struct Banner1 *banner1 = tcpcon->banner1; stream = banner1->payloads.tcp[port_them]; } tcb->stream = stream; banout_init(&tcb->banout); /* The TCB is now allocated/in-use */ assert(tcb->ip_me.version != 0 && tcb->ip_them.version != 0); tcb->is_active = 1; tcpcon->active_count++; tcpcon_lookup_tcb(tcpcon, ip_me, ip_them, port_me, port_them); return tcb; } /*************************************************************************** ***************************************************************************/ struct TCP_Control_Block * tcpcon_lookup_tcb( struct TCP_ConnectionTable *tcpcon, ipaddress ip_me, ipaddress ip_them, unsigned port_me, unsigned port_them) { unsigned index; struct TCP_Control_Block tmp; struct TCP_Control_Block *tcb; ipaddress_formatted_t fmt1; ipaddress_formatted_t fmt2; tmp.ip_me = ip_me; tmp.ip_them = ip_them; tmp.port_me = (unsigned short)port_me; tmp.port_them = (unsigned short)port_them; index = tcb_hash(ip_me, port_me, ip_them, port_them, tcpcon->entropy); fmt1 = ipaddress_fmt(ip_me); fmt2 = ipaddress_fmt(ip_them); LOG(1, "tcb_hash(0x%08x) = %s %u %s %u\n", (unsigned)index, fmt1.string, port_me, fmt2.string, port_them); /* Hash to an entry in the table, then follow a linked list from * that point forward. */ tcb = tcpcon->entries[index & tcpcon->mask]; while (tcb && !TCB_EQUALS(tcb, &tmp)) { tcb = tcb->next; } return tcb; } /*************************************************************************** ***************************************************************************/ static void tcpcon_send_packet( struct TCP_ConnectionTable *tcpcon, struct TCP_Control_Block *tcb, unsigned tcp_flags, const unsigned char *payload, size_t payload_length) { struct PacketBuffer *response = 0; unsigned is_syn = (tcp_flags == 0x02); assert(tcb->ip_me.version != 0 && tcb->ip_them.version != 0); /* If sending an ACK, print a message */ if ((tcp_flags & 0x10) == 0x10) { LOGtcb(tcb, 0, "xmit ACK ackingthem=%u\n", tcb->seqno_them-tcb->seqno_them_first); } /* Get a buffer for sending the response packet. This thread doesn't * send the packet itself. Instead, it formats a packet, then hands * that packet off to a transmit thread for later transmission. */ response = stack_get_packetbuffer(tcpcon->stack); if (response == NULL) { static int is_warning_printed = 0; if (!is_warning_printed) { LOG(0, "packet buffers empty (should be impossible)\n"); is_warning_printed = 1; } fflush(stdout); /* FIXME: I'm no sure the best way to handle this. * This would result from a bug in the code, * but I'm not sure what should be done in response */ pixie_usleep(100); /* no packet available */ } if (response == NULL) return; /* Format the packet as requested. Note that there are really only * four types of packets: * 1. a SYN-ACK packet with no payload * 2. an ACK packet with no payload * 3. a RST packet with no payload * 4. a PSH-ACK packet WITH PAYLOAD */ response->length = tcp_create_packet( tcpcon->pkt_template, tcb->ip_them, tcb->port_them, tcb->ip_me, tcb->port_me, tcb->seqno_me - is_syn, tcb->seqno_them, tcp_flags, payload, payload_length, response->px, sizeof(response->px) ); /* * KLUDGE: */ if (tcb->is_small_window) tcp_set_window(response->px, response->length, 600); /* Put this buffer on the transmit queue. Remember: transmits happen * from a transmit-thread only, and this function is being called * from a receive-thread. Therefore, instead of transmiting ourselves, * we hae to queue it up for later transmission. */ stack_transmit_packetbuffer(tcpcon->stack, response); } /*************************************************************************** ***************************************************************************/ void tcp_send_RST( struct TemplatePacket *templ, struct stack_t *stack, ipaddress ip_them, ipaddress ip_me, unsigned port_them, unsigned port_me, unsigned seqno_them, unsigned seqno_me ) { struct PacketBuffer *response = 0; /* Get a buffer for sending the response packet. This thread doesn't * send the packet itself. Instead, it formats a packet, then hands * that packet off to a transmit thread for later transmission. */ response = stack_get_packetbuffer(stack); if (response == NULL) { static int is_warning_printed = 0; if (!is_warning_printed) { LOG(0, "packet buffers empty (should be impossible)\n"); is_warning_printed = 1; } fflush(stdout); pixie_usleep(100); /* no packet available */ } if (response == NULL) return; response->length = tcp_create_packet( templ, ip_them, port_them, ip_me, port_me, seqno_me, seqno_them, 0x04, /*RST*/ 0, 0, response->px, sizeof(response->px) ); /* Put this buffer on the transmit queue. Remember: transmits happen * from a transmit-thread only, and this function is being called * from a receive-thread. Therefore, instead of transmitting ourselves, * we have to queue it up for later transmission. */ stack_transmit_packetbuffer(stack, response); } /*************************************************************************** * DEBUG: when printing debug messages (-d option), this prints a string * for the given state. ***************************************************************************/ static const char * what_to_string(enum TCP_What state) { static char buf[64]; switch (state) { case TCP_WHAT_TIMEOUT: return "TIMEOUT"; case TCP_WHAT_SYNACK: return "SYNACK"; case TCP_WHAT_RST: return "RST"; case TCP_WHAT_FIN: return "FIN"; case TCP_WHAT_ACK: return "ACK"; case TCP_WHAT_DATA: return "DATA"; case TCP_WHAT_CLOSE: return "CLOSE"; default: snprintf(buf, sizeof(buf), "%d", state); return buf; } } /*************************************************************************** ***************************************************************************/ static void LOGSEND(struct TCP_Control_Block *tcb, const char *what) { if (tcb == NULL) return; LOGip(5, tcb->ip_them, tcb->port_them, "=%s : --->> %s \n", state_to_string(tcb->tcpstate), what); } void tcpcon_send_RST( struct TCP_ConnectionTable *tcpcon, ipaddress ip_me, ipaddress ip_them, unsigned port_me, unsigned port_them, uint32_t seqno_them, uint32_t ackno_them) { struct TCP_Control_Block tcb; memset(&tcb, 0, sizeof(tcb)); tcb.ip_me = ip_me; tcb.ip_them = ip_them; tcb.port_me = (unsigned short)port_me; tcb.port_them = (unsigned short)port_them; tcb.seqno_me = ackno_them; tcb.ackno_me = seqno_them + 1; tcb.seqno_them = seqno_them + 1; tcb.ackno_them = ackno_them; LOGSEND(&tcb, "send RST"); tcpcon_send_packet(tcpcon, &tcb, 0x04 /*RST*/, 0, 0); } /*************************************************************************** * Called upon timeouts when an acknowledgement hasn't been received in * time. Will resend the segments. ***************************************************************************/ static void _tcb_seg_resend(struct TCP_ConnectionTable *tcpcon, struct TCP_Control_Block *tcb) { struct TCP_Segment *seg = tcb->segments; if (seg) { if (tcb->seqno_me != seg->seqno) { ERRMSG("SEQNO FAILURE diff=%d %s\n", tcb->seqno_me - seg->seqno, seg->is_fin?"FIN":""); return; } if (seg->is_fin && seg->length == 0) { tcpcon_send_packet(tcpcon, tcb, 0x11, /*FIN-ACK*/ 0, /*FIN has no data */ 0 /*logically is 1 byte, but not payload byte */); } else { tcpcon_send_packet(tcpcon, tcb, 0x18 | (seg->is_fin?0x01:0x00), seg->buf, seg->length); } } } /*************************************************************************** ***************************************************************************/ static unsigned application_notify(struct TCP_ConnectionTable *tcpcon, struct TCP_Control_Block *tcb, enum App_Event event, const void *payload, size_t payload_length, unsigned secs, unsigned usecs) { struct Banner1 *banner1 = tcpcon->banner1; const struct ProtocolParserStream *stream = tcb->stream; struct stack_handle_t socket = { tcpcon, tcb, secs, usecs}; return application_event(&socket, tcb->app_state, event, stream, banner1, payload, payload_length ); } /*************************************************************************** ***************************************************************************/ static void _tcb_seg_send(void *in_tcpcon, void *in_tcb, const void *buf, size_t length, enum TCP__flags flags) { struct TCP_ConnectionTable *tcpcon = (struct TCP_ConnectionTable *)in_tcpcon; struct TCP_Control_Block *tcb = (struct TCP_Control_Block *)in_tcb; struct TCP_Segment *seg; struct TCP_Segment **next; unsigned seqno = tcb->seqno_me; size_t length_more = 0; bool is_fin = (flags == TCP__close_fin); if (length > tcb->mss) { length_more = length - tcb->mss; length = tcb->mss; } if (length == 0 && !is_fin) return; /* Go to the end of the segment list */ for (next = &tcb->segments; *next; next = &(*next)->next) { seqno = (unsigned)((*next)->seqno + (*next)->length); if ((*next)->is_fin) { /* can't send past a FIN */ LOGip(0, tcb->ip_them, tcb->port_them, "can't send past a FIN\n"); if (flags == TCP__adopt) { free((void*)buf); /* discard const */ buf = NULL; } return; } } /* Append this segment to the list */ seg = calloc(1, sizeof(*seg)); *next = seg; /* Fill in this segment's members */ seg->seqno = seqno; seg->length = length; seg->flags = flags; switch (flags) { case TCP__static: case TCP__adopt: seg->buf = (void *)buf; break; case TCP__copy: seg->buf = malloc(length); memcpy(seg->buf, buf, length); break; case TCP__close_fin: seg->buf = 0; break; } if (length_more == 0) seg->is_fin = is_fin; if (!seg->is_fin && seg->length && tcb->tcpstate != STATE_ESTABLISHED_SEND) application_notify(tcpcon, tcb, APP_SENDING, seg->buf, seg->length, 0, 0); LOGtcb(tcb, 0, "send = %u-bytes %s @ %u\n", length, is_fin?"FIN":"", seg->seqno-tcb->seqno_me_first); /* If this is the head of the segment list, then transmit right away */ if (tcb->segments == seg) { LOGtcb(tcb, 0, "xmit = %u-bytes %s @ %u\n", length, is_fin?"FIN":"", seg->seqno-tcb->seqno_me_first); tcpcon_send_packet(tcpcon, tcb, 0x18 | (is_fin?1:0), seg->buf, seg->length); if (!is_fin) _tcb_change_state_to(tcb, STATE_ESTABLISHED_SEND); } /* If the input buffer was too large to fit a single segment, then * split it up into multiple segments */ if (length_more) { if (flags == TCP__adopt) flags = TCP__copy; _tcb_seg_send(tcpcon, tcb, (unsigned char*)buf + length, length_more, flags); } //tcb->established = App_SendNext; } /*************************************************************************** ***************************************************************************/ static int _tcp_seg_acknowledge( struct TCP_Control_Block *tcb, uint32_t ackno) { /*LOG(4, "%s - %u-sending, %u-reciving\n", fmt.string, tcb->seqno_me - ackno, ackno - tcb->ackno_them );*/ /* Normal: just discard repeats */ if (ackno == tcb->seqno_me) { return 0; } /* Make sure this isn't a duplicate ACK from past * WRAPPING of 32-bit arithmetic happens here */ if (ackno - tcb->seqno_me > 100000) { ipaddress_formatted_t fmt = ipaddress_fmt(tcb->ip_them); LOG(4, "%s - " "tcb: ackno from past: " "old ackno = 0x%08x, this ackno = 0x%08x\n", fmt.string, tcb->ackno_me, ackno); return 0; } /* Make sure this isn't invalid ACK from the future * WRAPPING of 32-bit arithmetic happens here */ if (tcb->seqno_me - ackno < 100000) { ipaddress_formatted_t fmt = ipaddress_fmt(tcb->ip_them); LOG(0, "%s - " "tcb: ackno from future: " "my seqno = 0x%08x, their ackno = 0x%08x\n", fmt.string, tcb->seqno_me, ackno); return 0; } /* Handle FIN specially */ handle_fin: if (tcb->segments && tcb->segments->is_fin) { struct TCP_Segment *seg = tcb->segments; if (seg->seqno+1 == ackno) { LOGtcb(tcb, 1, "ACKed FIN\n"); tcb->seqno_me += 1; tcb->ackno_them += 1; return 1; } else if (seg->seqno == ackno) { return 0; } else { LOGtcb(tcb, 1, "@@@@@BAD ACK of FIN@@@@\n", seg->length); return 0; } } /* Retire outstanding segments */ { unsigned length = ackno - tcb->seqno_me; while (tcb->segments && length >= tcb->segments->length) { struct TCP_Segment *seg = tcb->segments; if (seg->is_fin) goto handle_fin; tcb->segments = seg->next; length -= seg->length; tcb->seqno_me += seg->length; tcb->ackno_them += seg->length; LOGtcb(tcb, 1, "ACKed %u-bytes\n", seg->length); /* free the old segment */ switch (seg->flags) { case TCP__static: break; case TCP__adopt: case TCP__copy: if (seg->buf) { free(seg->buf); seg->buf = NULL; } break; default: ; } free(seg); if (ackno == tcb->ackno_them) return 1; /* good ACK */ } if (tcb->segments && length < tcb->segments->length) { struct TCP_Segment *seg = tcb->segments; tcb->seqno_me += length + seg->is_fin; tcb->ackno_them += length + seg->is_fin; LOGtcb(tcb, 1, "ACKed %u-bytes %s\n", length, seg->is_fin?"FIN":""); /* This segment needs to be reduced */ if (seg->flags == TCP__adopt || seg->flags == TCP__copy) { size_t new_length = seg->length - length; unsigned char *buf = malloc(new_length); memcpy(buf, seg->buf + length, new_length); free(seg->buf); seg->buf = buf; seg->length -= length; seg->flags = TCP__copy; } else { seg->buf += length; } } } /* Mark that this was a good ack */ return 1; } void banner_set_sslhello(struct stack_handle_t *socket, bool is_true) { struct TCP_Control_Block *tcb = socket->tcb; tcb->banner1_state.is_sent_sslhello = is_true; } void banner_set_small_window(struct stack_handle_t *socket, bool is_true) { struct TCP_Control_Block *tcb = socket->tcb; tcb->is_small_window = is_true; } bool banner_is_heartbleed(const struct stack_handle_t *socket) { struct TCP_ConnectionTable *tcpcon = socket->tcpcon; return tcpcon->banner1->is_heartbleed != 0; } /*************************************************************************** * Parse the information we get from the server we are scanning. Typical * examples are SSH banners, FTP banners, or the response from HTTP * requests ***************************************************************************/ size_t banner_parse( struct stack_handle_t *socket, const unsigned char *payload, size_t payload_length ) { struct TCP_ConnectionTable *tcpcon = socket->tcpcon; struct TCP_Control_Block *tcb = socket->tcb; assert(tcb->banout.max_length); banner1_parse( tcpcon->banner1, &tcb->banner1_state, payload, payload_length, &tcb->banout, socket); return payload_length; } /*************************************************************************** ***************************************************************************/ static void _next_IP_port(struct TCP_ConnectionTable *tcpcon, ipaddress *ip_me, unsigned *port_me) { const struct stack_src_t *src = tcpcon->stack->src; unsigned index; /* Get another source port, because we can't use the existing * one for new connection */ index = *port_me - src->port.first + 1; *port_me = src->port.first + index; if (*port_me >= src->port.last) { *port_me = src->port.first; /* We've wrapped the ports, so therefore choose another source * IP address as well. */ switch (ip_me->version) { case 4: index = ip_me->ipv4 - src->ipv4.first + 1; ip_me->ipv4 = src->ipv4.first + index; if (ip_me->ipv4 >= src->ipv4.last) ip_me->ipv4 = src->ipv4.first; break; case 6: { /* TODO: this code is untested, yolo */ ipv6address_t diff; diff = ipv6address_subtract(ip_me->ipv6, src->ipv6.first); diff = ipv6address_add_uint64(diff, 1); ip_me->ipv6 = ipv6address_add(src->ipv6.first, diff); if (ipv6address_is_lessthan(src->ipv6.last, ip_me->ipv6)) ip_me->ipv6 = src->ipv6.first; break; } default: break; } } } /*************************************************************************** ***************************************************************************/ static void _do_reconnect(struct TCP_ConnectionTable *tcpcon, const struct TCP_Control_Block *old_tcb, const struct ProtocolParserStream *stream, unsigned secs, unsigned usecs, unsigned established) { struct TCP_Control_Block *new_tcb; ipaddress ip_them = old_tcb->ip_them; unsigned port_them = old_tcb->port_them; ipaddress ip_me = old_tcb->ip_me; unsigned port_me = old_tcb->port_me; unsigned seqno; /* * First, get another port number and potentially ip address */ { ipaddress prev_ip = ip_me; unsigned prev_port = port_me; _next_IP_port(tcpcon, &ip_me, &port_me); if (ipaddress_is_equal(ip_me, prev_ip) && port_me == prev_port) ERRMSG("There must be multiple source ports/addresses for reconnection\n"); } /* * Calculate the SYN cookie, the same algorithm as for when spewing * SYN packets. However, since we'll probably be using a different * port or IP address, it'll be different in practice. */ seqno = (unsigned)syn_cookie(ip_them, port_them, ip_me, port_me, tcpcon->entropy); /* * Now create a new TCB for this new connection */ new_tcb = tcpcon_create_tcb( tcpcon, ip_me, ip_them, port_me, port_them, seqno+1, 0, 255, stream, secs, usecs); new_tcb->app_state = established; } static void _tcb_seg_close(void *in_tcpcon, void *in_tcb, unsigned secs, unsigned usecs) { struct TCP_ConnectionTable *tcpcon = (struct TCP_ConnectionTable *)in_tcpcon; struct TCP_Control_Block *tcb = (struct TCP_Control_Block *)in_tcb; stack_incoming_tcp(tcpcon, tcb, TCP_WHAT_CLOSE, 0, 0, secs, usecs, tcb->seqno_them, tcb->ackno_them); } /*************************************************************************** ***************************************************************************/ int tcpapi_set_timeout(struct stack_handle_t *socket, unsigned secs, unsigned usecs ) { struct TCP_ConnectionTable *tcpcon = socket->tcpcon; struct TCP_Control_Block *tcb = socket->tcb; if (socket == NULL) return SOCKERR_EBADF; timeouts_add(tcpcon->timeouts, tcb->timeout, offsetof(struct TCP_Control_Block, timeout), TICKS_FROM_TV(socket->secs+secs, socket->usecs + usecs) ); return 0; } /*************************************************************************** ***************************************************************************/ int tcpapi_recv(struct stack_handle_t *socket) { struct TCP_Control_Block *tcb; if (socket == 0 || socket->tcb == 0) return SOCKERR_EBADF; tcb = socket->tcb; switch (tcb->tcpstate) { default: case STATE_ESTABLISHED_SEND: _tcb_change_state_to(socket->tcb, STATE_ESTABLISHED_RECV); break; case STATE_FIN_WAIT1_RECV: _tcb_change_state_to(socket->tcb, STATE_FIN_WAIT1_RECV); break; case STATE_FIN_WAIT1_SEND: _tcb_change_state_to(socket->tcb, STATE_FIN_WAIT1_RECV); break; } return 0; } int tcpapi_send(struct stack_handle_t *socket, const void *buf, size_t length, enum TCP__flags flags) { struct TCP_Control_Block *tcb; if (socket == 0 || socket->tcb == 0) return SOCKERR_EBADF; tcb = socket->tcb; switch (tcb->tcpstate) { case STATE_ESTABLISHED_RECV: _tcb_change_state_to(tcb, STATE_ESTABLISHED_SEND); /*follow through*/ case STATE_ESTABLISHED_SEND: _tcb_seg_send(socket->tcpcon, tcb, buf, length, flags); return 0; default: LOG(1, "TCP app attempted SEND in wrong state\n"); return 1; } } int tcpapi_reconnect(struct stack_handle_t *old_socket, struct ProtocolParserStream *new_stream, unsigned new_app_state) { if (old_socket == 0 || old_socket->tcb == 0) return SOCKERR_EBADF; _do_reconnect(old_socket->tcpcon, old_socket->tcb, new_stream, old_socket->secs, old_socket->usecs, new_app_state); return 0; } unsigned tcpapi_change_app_state(struct stack_handle_t *socket, unsigned new_app_state) { struct TCP_Control_Block *tcb; if (socket == 0 || socket->tcb == 0) return SOCKERR_EBADF; tcb = socket->tcb; //printf("%u --> %u\n", tcb->app_state, new_app_state); tcb->app_state = new_app_state; return new_app_state; } int tcpapi_close(struct stack_handle_t *socket) { if (socket == NULL || socket->tcb == NULL) return SOCKERR_EBADF; _tcb_seg_close(socket->tcpcon, socket->tcb, socket->secs, socket->usecs); return 0; } static bool _tcb_they_have_acked_my_fin(struct TCP_Control_Block *tcb) { if (tcb->segments && tcb->segments->is_fin && tcb->segments->length == 0) { if (tcb->ackno_them >= tcb->segments->seqno + 1) return true; return false; } else return false; } static void _tcb_send_ack(struct TCP_ConnectionTable *tcpcon, struct TCP_Control_Block *tcb) { tcpcon_send_packet(tcpcon, tcb, 0x10, 0, 0); } static int _tcb_seg_recv(struct TCP_ConnectionTable *tcpcon, struct TCP_Control_Block *tcb, const unsigned char *payload, size_t payload_length, unsigned seqno_them, unsigned secs, unsigned usecs, bool is_fin) { /* Special case when packet contains only a FIN */ if (payload_length == 0 && is_fin && (tcb->seqno_them - seqno_them) == 0) { tcb->is_their_fin = 1; tcb->seqno_them += 1; tcb->ackno_me += 1; tcpcon_send_packet(tcpcon, tcb, 0x10/*ACK*/, 0, 0); return 1; } if ((tcb->seqno_them - seqno_them) > payload_length) { LOGSEND(tcb, "peer(ACK) [acknowledge payload 1]"); tcpcon_send_packet(tcpcon, tcb, 0x10 /*ACK*/, 0, 0); return 1; } while (seqno_them != tcb->seqno_them && payload_length) { seqno_them++; payload_length--; payload++; } if (tcb->is_their_fin) { /* payload cannot be received after a FIN */ return 1; } if (payload_length == 0) { tcpcon_send_packet(tcpcon, tcb, 0x10/*ACK*/, 0, 0); return 1; } LOGtcb(tcb, 2, "received %u bytes\n", payload_length); tcb->seqno_them += payload_length + is_fin; tcb->ackno_me += payload_length + is_fin; application_notify(tcpcon, tcb, APP_RECV_PAYLOAD, payload, payload_length, secs, usecs); if (is_fin) tcb->is_their_fin = true; /* Send ack for the data */ _tcb_send_ack(tcpcon, tcb); return 0; } /***************************************************************************** * Handles incoming events, like timeouts and packets, that cause a change * in the TCP control block "state". * * This is the part of the code that implements the famous TCP state-machine * you see drawn everywhere, where they have states like "TIME_WAIT". Only * we don't really have those states. *****************************************************************************/ enum TCB_result stack_incoming_tcp(struct TCP_ConnectionTable *tcpcon, struct TCP_Control_Block *tcb, enum TCP_What what, const unsigned char *payload, size_t payload_length, unsigned secs, unsigned usecs, unsigned seqno_them, unsigned ackno_them) { /* FILTER * Reject out-of-order payloads */ if (payload_length) { /* Wrapping technique: If there is a gap between this * packet and the last one, then it means there is a missing * packet somewhere. In that case, this calculation will * wrap and `payload_offset` will be some huge number in the future. * If there is no gap, then this will be zero. * If there's overlap between this packet and the previous, `payload_offset` * will be a small number less than the `length` of this packet. * If it's a retransmission, the numbers will be the same */ int payload_offset = seqno_them - tcb->seqno_them; if (payload_offset < 0) { /* This is a retrnasmission that we've already acknowledged */ if (payload_offset <= 0 - (int)payload_length) { /* Both begin and end are old, so simply discard it */ return TCB__okay; } else { /* Otherwise shorten the payload */ payload_length += payload_offset; payload -= payload_offset; seqno_them -= payload_offset; assert(payload_length < 2000); } } else if (payload_offset > 0) { /* This is an out-of-order fragment in the future. an important design * of this light-weight stack is that we don't support this, and * force the other side to retransmit such packets */ return TCB__okay; } } /* FILTER: * Reject out-of-order FINs. * Handle duplicate FINs here */ if (what == TCP_WHAT_FIN) { if (seqno_them == tcb->seqno_them - 1) { /* Duplicate FIN, respond with ACK */ LOGtcb(tcb, 1, "duplicate FIN\n"); _tcb_send_ack(tcpcon, tcb); return TCB__okay; } else if (seqno_them != tcb->seqno_them) { /* out of order FIN, so drop it */ LOGtcb(tcb, 1, "out-of-order FIN\n"); return TCB__okay; } } LOGtcb(tcb, 1, "##%s##\n", what_to_string(what)); /* Make sure no connection lasts longer than ~30 seconds */ if (what == TCP_WHAT_TIMEOUT) { if (tcb->when_created + tcpcon->timeout_connection < secs) { LOGip(8, tcb->ip_them, tcb->port_them, "%s \n", "CONNECTION TIMEOUT---"); LOGSEND(tcb, "peer(RST)"); tcpcon_send_packet(tcpcon, tcb, 0x04 /*RST*/, 0, 0); tcpcon_destroy_tcb(tcpcon, tcb, Reason_Timeout); return TCB__destroyed; } } if (what == TCP_WHAT_RST) { LOGSEND(tcb, "tcb(destroy)"); tcpcon_destroy_tcb(tcpcon, tcb, Reason_RST); return TCB__destroyed; } /* * * * * * * */ switch (tcb->tcpstate) { /* TODO: validate any SYNACK is real before sending it here * to the state-machine, by validating that it's acking * something */ case STATE_SYN_SENT: switch (what) { case TCP_WHAT_TIMEOUT: /* We've sent a SYN, but didn't get SYN-ACK, so * send another */ tcb->syns_sent++; /* Send a SYN */ tcpcon_send_packet(tcpcon, tcb, 0x02 /*SYN*/, 0, 0); break; case TCP_WHAT_SYNACK: tcb->seqno_them = seqno_them; tcb->seqno_them_first = seqno_them - 1; tcb->seqno_me = ackno_them; tcb->seqno_me_first = ackno_them - 1; LOGtcb(tcb, 1, "%s connection established\n", what_to_string(what)); /* Send "ACK" to acknowlege their "SYN-ACK" */ _tcb_send_ack(tcpcon, tcb); _tcb_change_state_to(tcb, STATE_ESTABLISHED_RECV); application_notify(tcpcon, tcb, APP_CONNECTED, 0, 0, secs, usecs); break; default: ERRMSGip(tcb->ip_them, tcb->port_them, "%s:%s **** UNHANDLED EVENT ****\n", state_to_string(tcb->tcpstate), what_to_string(what)); break; } break; case STATE_ESTABLISHED_SEND: switch (what) { case TCP_WHAT_CLOSE: _tcb_seg_send(tcpcon, tcb, 0, 0, TCP__close_fin); _tcb_change_state_to(tcb, STATE_FIN_WAIT1_SEND); break; case TCP_WHAT_FIN: if (seqno_them == tcb->seqno_them) { /* I have ACKed all their data, so therefore process this */ _tcb_seg_recv(tcpcon, tcb, 0, 0, seqno_them, secs, usecs, true); _tcb_change_state_to(tcb, STATE_FIN_WAIT1_SEND); _tcb_send_ack(tcpcon, tcb); } else { /* I haven't received all their data, so ignore it until I do */ _tcb_send_ack(tcpcon, tcb); } break; case TCP_WHAT_ACK: _tcp_seg_acknowledge(tcb, ackno_them); if (tcb->segments == NULL || tcb->segments->length == 0) { /* We've finished sending everything, so switch our application state * back to sending */ _tcb_change_state_to(tcb, STATE_ESTABLISHED_RECV); /* All the payload has been sent. Notify the application of this, so that they * can send more if the want, or switch to listening. */ application_notify(tcpcon, tcb, APP_SEND_SENT, 0, 0, secs, usecs); } break; case TCP_WHAT_TIMEOUT: /* They haven't acknowledged everything yet, so resend the last segment */ _tcb_seg_resend(tcpcon, tcb); break; case TCP_WHAT_DATA: /* We don't receive data while in the sending state. We force them * to keep re-sending it until we are prepared to receive it. This * saves us from having to buffer it in this stack. */ break; case TCP_WHAT_SYNACK: break; default: ERRMSGip(tcb->ip_them, tcb->port_them, "%s:%s **** UNHANDLED EVENT ****\n", state_to_string(tcb->tcpstate), what_to_string(what)); break; } break; case STATE_ESTABLISHED_RECV: switch (what) { case TCP_WHAT_CLOSE: _tcb_seg_send(tcpcon, tcb, 0, 0, TCP__close_fin); _tcb_change_state_to(tcb, STATE_FIN_WAIT1_RECV); break; case TCP_WHAT_FIN: if (seqno_them == tcb->seqno_them) { /* I have ACKed all their data, so therefore process this */ _tcb_seg_recv(tcpcon, tcb, 0, 0, seqno_them, secs, usecs, true); _tcb_change_state_to(tcb, STATE_CLOSE_WAIT); //_tcb_send_ack(tcpcon, tcb); application_notify(tcpcon, tcb, APP_CLOSE, 0, payload_length, secs, usecs); } else { /* I haven't received all their data, so ignore it until I do */ _tcb_send_ack(tcpcon, tcb); } break; case TCP_WHAT_ACK: _tcp_seg_acknowledge(tcb, ackno_them); break; case TCP_WHAT_TIMEOUT: application_notify(tcpcon, tcb, APP_RECV_TIMEOUT, 0, 0, secs, usecs); break; case TCP_WHAT_DATA: _tcb_seg_recv(tcpcon, tcb, payload, payload_length, seqno_them, secs, usecs, false); break; case TCP_WHAT_SYNACK: /* This happens when a delayed SYN-ACK arrives from the target. * I see these fairly often from host 178.159.37.125. * We are going to make them silent for now, but eventually, keep * statistics about this sort of thing. */ break; default: ERRMSGip(tcb->ip_them, tcb->port_them, "%s:%s **** UNHANDLED EVENT ****\n", state_to_string(tcb->tcpstate), what_to_string(what)); break; } break; /* SYN-RCVD + FIN = FIN-WAIT-1 ESTAB + FIN = FIN-WAIT-1 +---------+ | FIN | | WAIT-1 | +---------+ FIN-WAIT-1 + FIN --> CLOSING FIN-WAIT-1 + ACK-of-FIN --> FIN-WAIT-2 */ case STATE_FIN_WAIT1_SEND: switch (what) { case TCP_WHAT_FIN: /* Ignore their FIN while in the SENDing state. */ break; case TCP_WHAT_ACK: /* Apply the ack */ if (_tcp_seg_acknowledge(tcb, ackno_them)) { /* Same a in ESTABLISHED_SEND, once they've acknowledged * all reception BEFORE THE FIN, then change the state */ if (tcb->segments == NULL || tcb->segments->length == 0) { /* All the payload has been sent. Notify the application of this, so that they * can send more if the want, or switch to listening. */ _tcb_change_state_to(tcb, STATE_FIN_WAIT1_RECV); application_notify(tcpcon, tcb, APP_SEND_SENT, 0, 0, secs, usecs); } } break; case TCP_WHAT_TIMEOUT: _tcb_seg_resend(tcpcon, tcb); /* also resends FINs */ break; case TCP_WHAT_DATA: /* Ignore any data received while in the SEND state */ break; default: ERRMSGip(tcb->ip_them, tcb->port_them, "%s:%s **** UNHANDLED EVENT ****\n", state_to_string(tcb->tcpstate), what_to_string(what)); break; } break; case STATE_FIN_WAIT1_RECV: switch (what) { case TCP_WHAT_FIN: _tcb_seg_recv(tcpcon, tcb, 0, 0, seqno_them, secs, usecs, true); _tcb_change_state_to(tcb, STATE_CLOSING); _tcb_send_ack(tcpcon, tcb); application_notify(tcpcon, tcb, APP_CLOSE, 0, 0, secs, usecs); break; case TCP_WHAT_ACK: /* Apply the ack */ if (_tcp_seg_acknowledge(tcb, ackno_them)) { if (_tcb_they_have_acked_my_fin(tcb)) { _tcb_change_state_to(tcb, STATE_FIN_WAIT2); application_notify(tcpcon, tcb, APP_CLOSE, 0, 0, secs, usecs); } } break; case TCP_WHAT_TIMEOUT: _tcb_seg_resend(tcpcon, tcb); /* also recv FIN */ break; case TCP_WHAT_DATA: _tcb_seg_recv(tcpcon, tcb, payload, payload_length, seqno_them, secs, usecs, false); break; default: ERRMSGip(tcb->ip_them, tcb->port_them, "%s:%s **** UNHANDLED EVENT ****\n", state_to_string(tcb->tcpstate), what_to_string(what)); break; } break; case STATE_CLOSING: switch (what) { case TCP_WHAT_TIMEOUT: tcpcon_destroy_tcb(tcpcon, tcb, Reason_Timeout); return TCB__destroyed; case TCP_WHAT_ACK: _tcp_seg_acknowledge(tcb, ackno_them); if (_tcb_they_have_acked_my_fin(tcb)) { tcpcon_destroy_tcb(tcpcon, tcb, Reason_FIN); return TCB__destroyed; } break; case TCP_WHAT_FIN: /* I've already acknowledged their FIN, but hey, do it again */ _tcb_send_ack(tcpcon, tcb); break; case TCP_WHAT_CLOSE: /* The application this machine has issued a second `tcpapi_close()` request. * This represents a bug in the application process. One place where I see this * when scanning 193.109.9.122:992. * FIXME TODO */ ; /* make this silent for now */ break; default: ERRMSGip(tcb->ip_them, tcb->port_them, "%s:%s **** UNHANDLED EVENT ****\n", state_to_string(tcb->tcpstate), what_to_string(what)); break; } break; case STATE_FIN_WAIT2: case STATE_TIME_WAIT: switch (what) { case TCP_WHAT_TIMEOUT: /* giving up */ if (tcb->tcpstate == STATE_TIME_WAIT) { tcpcon_destroy_tcb(tcpcon, tcb, Reason_Timeout); return TCB__destroyed; } break; case TCP_WHAT_ACK: break; case TCP_WHAT_FIN: /* Processing incoming FIN as an empty paylaod */ _tcb_seg_recv(tcpcon, tcb, 0, 0, seqno_them, secs, usecs, true); _tcb_change_state_to(tcb, STATE_TIME_WAIT); timeouts_add( tcpcon->timeouts, tcb->timeout, offsetof(struct TCP_Control_Block, timeout), TICKS_FROM_TV(secs+5,usecs) ); break; case TCP_WHAT_SYNACK: case TCP_WHAT_RST: case TCP_WHAT_DATA: break; case TCP_WHAT_CLOSE: /* FIXME: to reach this state, we've already done a close. * FIXME: but this happens twice, because only have * FIXME: a single close function. */ break; default: ERRMSGip(tcb->ip_them, tcb->port_them, "%s:%s **** UNHANDLED EVENT ****\n", state_to_string(tcb->tcpstate), what_to_string(what)); break; } break; case STATE_CLOSE_WAIT: /* Waiting for app to call `close()` */ switch (what) { case TCP_WHAT_CLOSE: _tcb_seg_send(tcpcon, tcb, 0, 0, TCP__close_fin); _tcb_change_state_to(tcb, STATE_LAST_ACK); break; case TCP_WHAT_TIMEOUT: /* Remind the app that it's waiting for it to be closed */ application_notify(tcpcon, tcb, APP_CLOSE, 0, payload_length, secs, usecs); break; default: ERRMSGip(tcb->ip_them, tcb->port_them, "%s:%s **** UNHANDLED EVENT ****\n", state_to_string(tcb->tcpstate), what_to_string(what)); break; } break; case STATE_LAST_ACK: switch (what) { case TCP_WHAT_TIMEOUT: /* They haven't acknowledged everything yet, so resend the last segment */ _tcb_seg_resend(tcpcon, tcb); break; case TCP_WHAT_ACK: if (_tcp_seg_acknowledge(tcb, ackno_them)) { tcpcon_destroy_tcb(tcpcon, tcb, Reason_Shutdown); return TCB__destroyed; } break; default: ERRMSGip(tcb->ip_them, tcb->port_them, "%s:%s **** UNHANDLED EVENT ****\n", state_to_string(tcb->tcpstate), what_to_string(what)); break; } break; break; default: ERRMSGip(tcb->ip_them, tcb->port_them, "%s:%s **** UNHANDLED EVENT ****\n", state_to_string(tcb->tcpstate), what_to_string(what)); break; } return TCB__okay; }
79,713
C
.c
1,995
29.568922
106
0.489043
robertdavidgraham/masscan
23,250
3,042
399
AGPL-3.0
9/7/2024, 9:40:14 AM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
5,460
main-ptrace.c
robertdavidgraham_masscan/src/main-ptrace.c
#include "main-ptrace.h" #include "proto-preprocess.h" #include "pixie-timer.h" #include "util-safefunc.h" /*************************************************************************** * Print packet info, when using nmap-style --packet-trace option ***************************************************************************/ void packet_trace(FILE *fp, double pt_start, const unsigned char *px, size_t length, unsigned is_sent) { unsigned x; struct PreprocessedInfo parsed; char from[64]; char to[64]; char sz_type[32]; unsigned type; double timestamp = 1.0 * pixie_gettime() / 1000000.0; unsigned offset; const char *direction; ipaddress_formatted_t fmt; if (is_sent) direction = "SENT"; else direction = "RCVD"; /* parse the packet */ x = preprocess_frame(px, (unsigned)length, 1, &parsed); if (!x) return; offset = parsed.found_offset; /* format the IP addresses into fixed-width fields */ fmt = ipaddress_fmt(parsed.src_ip); snprintf(from, sizeof(from), "[%s]:%u", fmt.string, parsed.port_src); fmt = ipaddress_fmt(parsed.dst_ip); snprintf(to, sizeof(to), "[%s]:%u", fmt.string, parsed.port_dst); switch (parsed.found) { case FOUND_ARP: type = px[offset+6]<<8 | px[offset+7]; *strchr(to, ':') = '\0'; *strchr(from, ':') = '\0'; switch (type) { case 1:safe_strcpy(sz_type, sizeof(sz_type), "request"); break; case 2:safe_strcpy(sz_type, sizeof(sz_type), "response"); break; default: snprintf(sz_type, sizeof(sz_type), "unknown(%u)", type); break; } fprintf(fp, "%s (%5.4f) ARP %-21s > %-21s %s\n", direction, timestamp - pt_start, from, to, sz_type); break; case FOUND_DNS: case FOUND_UDP: fprintf(fp, "%s (%5.4f) UDP %-21s > %-21s \n", direction, timestamp - pt_start, from, to); break; case FOUND_ICMP: fprintf(fp, "%s (%5.4f) ICMP %-21s > %-21s \n", direction, timestamp - pt_start, from, to); break; case FOUND_TCP: type = px[offset+13]; switch (type) { case 0x00: safe_strcpy(sz_type, sizeof(sz_type), "NULL"); break; case 0x01: safe_strcpy(sz_type, sizeof(sz_type), "FIN"); break; case 0x11: safe_strcpy(sz_type, sizeof(sz_type), "FIN-ACK"); break; case 0x19: safe_strcpy(sz_type, sizeof(sz_type), "FIN-ACK-PSH"); break; case 0x02: safe_strcpy(sz_type, sizeof(sz_type), "SYN"); break; case 0x12: safe_strcpy(sz_type, sizeof(sz_type), "SYN-ACK"); break; case 0x04: safe_strcpy(sz_type, sizeof(sz_type), "RST"); break; case 0x14: safe_strcpy(sz_type, sizeof(sz_type), "RST-ACK"); break; case 0x15: safe_strcpy(sz_type, sizeof(sz_type), "RST-FIN-ACK"); break; case 0x10: safe_strcpy(sz_type, sizeof(sz_type), "ACK"); break; case 0x18: safe_strcpy(sz_type, sizeof(sz_type), "ACK-PSH"); break; default: snprintf(sz_type, sizeof(sz_type), "%s%s%s%s%s%s%s%s", (type&0x01)?"FIN":"", (type&0x02)?"SYN":"", (type&0x04)?"RST":"", (type&0x08)?"PSH":"", (type&0x10)?"ACK":"", (type&0x20)?"URG":"", (type&0x40)?"ECE":"", (type&0x80)?"CWR":"" ); break; } if (parsed.app_length) fprintf(fp, "%s (%5.4f) TCP %-21s > %-21s %s %u-bytes\n", direction, timestamp - pt_start, from, to, sz_type, parsed.app_length); else fprintf(fp, "%s (%5.4f) TCP %-21s > %-21s %s\n", direction, timestamp - pt_start, from, to, sz_type); break; case FOUND_IPV6: break; default: fprintf(fp, "%s (%5.4f) UNK %-21s > %-21s [%u]\n", direction, timestamp - pt_start, from, to, parsed.found); break; } }
4,423
C
.c
99
32.080808
97
0.479601
robertdavidgraham/masscan
23,250
3,042
399
AGPL-3.0
9/7/2024, 9:40:14 AM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
5,463
util-extract.c
robertdavidgraham_masscan/src/util-extract.c
#include "util-extract.h" unsigned char e_next_byte(struct ebuf_t *ebuf) { if (ebuf->offset + 1 > ebuf->max) return -1; return ebuf->buf[ebuf->offset++]; } unsigned short e_next_short16(struct ebuf_t *ebuf, int endian) { const unsigned char *buf = ebuf->buf; size_t offset = ebuf->offset; unsigned short result; if (ebuf->offset + 2 > ebuf->max) return -1; if (endian == EBUF_BE) { result = buf[offset+0]<<8 | buf[offset+1]; } else { result = buf[offset+1]<<8 | buf[offset+0]; } ebuf->offset += 2; return result; } unsigned e_next_int32(struct ebuf_t *ebuf, int endian) { const unsigned char *buf = ebuf->buf; size_t offset = ebuf->offset; unsigned result; if (ebuf->offset + 4 > ebuf->max) return -1; if (endian == EBUF_BE) { result = buf[offset+0]<<24 | buf[offset+1] << 16 | buf[offset+2]<<8 | buf[offset+3] << 0; } else { result = buf[offset+3]<<24 | buf[offset+2] << 16 | buf[offset+1]<<8 | buf[offset+0] << 0; } ebuf->offset += 4; return result; } unsigned long long e_next_long64(struct ebuf_t *ebuf, int endian) { const unsigned char *buf = ebuf->buf; size_t offset = ebuf->offset; unsigned long long hi; unsigned long long lo; if (ebuf->offset + 8 > ebuf->max) return -1ll; if (endian == EBUF_BE) { hi = buf[offset+0]<<24 | buf[offset+1] << 16 | buf[offset+2]<<8 | buf[offset+3] << 0; lo = buf[offset+4]<<24 | buf[offset+5] << 16 | buf[offset+6]<<8 | buf[offset+7] << 0; } else { lo = buf[offset+3]<<24 | buf[offset+2] << 16 | buf[offset+1]<<8 | buf[offset+0] << 0; hi = buf[offset+7]<<24 | buf[offset+6] << 16 | buf[offset+5]<<8 | buf[offset+4] << 0; } ebuf->offset += 8; return hi<<32ull | lo; }
1,972
C
.c
60
25.783333
60
0.541158
robertdavidgraham/masscan
23,250
3,042
399
AGPL-3.0
9/7/2024, 9:40:14 AM (Europe/Amsterdam)
false
false
false
false
false
false
false
false