-
Notifications
You must be signed in to change notification settings - Fork 1
/
argparser.h
151 lines (122 loc) · 3.78 KB
/
argparser.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
#ifndef __ARGPARSER_H__
#define __ARGPARSER_H__
#include <stdio.h>
#include <string.h>
#include <getopt.h>
#define VERSION "0.9"
/*
* Cmdline options
*/
struct options_t {
char *victim_ip; // victim ip address
char *victim_mac; // victim mac address
char *our_ip; // our ip address
char *our_mac; // our mac address
char *device; // interface
int sleep_time; // sleep time in microseconds
int list_devices; // list all available network devices
int no_cksum; // disable packet checksum
int no_size; // disable packet size
int verbosity; // verbosity level
int print_dis; // enable disassembling and pretty printing
} options;
/*
* Program usage template
*/
const char usage_template[] =
"PortStealer " VERSION " [MitM tool for ethernet LANs]\n"
"written by: BUG L'Aquila, Emanuele Acri <crossbower@gmail.com>\n\n"
"Usage:\n"
" portstealer <options> victim_ip victim_mac our_ip our_mac\n"
"\nOptions:\n"
" -i <device> network device to use\n"
" -t <time> sleep time in microseconds (default 100000)\n"
" -v increment verbosity\n"
" -l list all available network devices\n"
"\nInjection options:\n"
" -C disable automatic packet checksum\n"
" -S disable automatic packet size\n"
"\nPretty printing and disassembling options:\n"
" -D enable disassembling (pretty printing) of packets\n"
"\nOther options:\n"
" -h help screen\n";
/*
* Program usage
*/
void usage(FILE *out, const char *error)
{
fputs(usage_template, out);
if(error)
fprintf(out, "\n%s\n", error);
exit(1);
}
/*
* Parser for command line options
* See getopt(3)...
*/
int parseopt(int argc, char **argv)
{
char *c=NULL, *x=NULL;
char ch;
// cleaning
memset(&options, 0, sizeof(options));
// default options
options.sleep_time = 100000;
const char *shortopt = "i:t:vlCSDh"; // short options
while ((ch = getopt (argc, argv, shortopt)) != -1) {
switch (ch) {
case 'i': // interface
options.device = optarg;
break;
case 't': // sleep time in microseconds
options.sleep_time = atoi(optarg);
break;
case 'v': // increment verbosity
options.verbosity++;
break;
case 'l': // list devices
options.list_devices = 1;
break;
case 'C': // disable packet checksum
options.no_cksum = 1;
break;
case 'S': // disable packet size
options.no_size = 1;
break;
case 'D': // enable disassembling and pretty printing
options.print_dis = 1;
break;
case 'h': //help
usage(stdout, NULL);
case '?':
default:
usage(stderr, NULL);
}
}
// get victim mac address
if(optind < argc) {
options.victim_ip = argv[optind];
} else {
usage(stderr, "Error: victim IP address not specified.");
}
// get victim mac address
if((optind + 1) < argc) {
options.victim_mac = argv[optind + 1];
} else {
usage(stderr, "Error: victim MAC address not specified.");
}
// get our ip address
if((optind + 2) < argc) {
options.our_ip = argv[optind + 2];
} else {
usage(stderr, "Error: our IP address not specified.");
}
// get our mac address
if((optind + 3) < argc) {
options.our_mac = argv[optind + 3];
} else {
usage(stderr, "Error: our MAC address not specified.");
}
return 1;
}
#endif /* __ARGPARSER_H__ */