|
43 | 43 | #include "inspect_utils.h" |
44 | 44 | #include "inspect_dns.h" |
45 | 45 |
|
46 | | -#define DEBUG_LOGS 0 |
47 | | - |
48 | | -#if DEBUG_LOGS |
49 | | -#define debug_log(...) \ |
50 | | - do { \ |
51 | | - fprintf(stderr, __VA_ARGS__); \ |
52 | | - fflush(stdout); \ |
53 | | - fputc('\n', stderr); \ |
54 | | - } while (0) |
55 | | -#else |
56 | | -#define debug_log(...) |
57 | | -#endif |
58 | | - |
59 | | -#define fatal_log(...) \ |
60 | | - do { \ |
61 | | - fprintf(stderr, __VA_ARGS__); \ |
62 | | - fputc('\n', stderr); \ |
63 | | - exit(EXIT_FAILURE); \ |
64 | | - } while (0) |
65 | | - |
66 | 46 | // The magic string that we'll use to detect full control over the command |
67 | 47 | // executed. |
68 | 48 | const std::string kTripWire = "/tmp/tripwire"; |
69 | 49 | // Shell injection bug confirmed with /tmp/tripwire. |
70 | 50 | const std::string kInjectionError = "Shell injection"; |
| 51 | +// Argument injection bug confirmed with --tripwire. |
| 52 | +const std::string kArgumentInjectionError = "Argument injection"; |
| 53 | +// The magic string we'll use to detect argument injection |
| 54 | +const std::string kArgumentTripWire = "--tripwire"; |
71 | 55 | // Shell corruption bug detected based on syntax error. |
72 | 56 | const std::string kCorruptionError = "Shell corruption"; |
73 | 57 | // The magic string that we'll use to detect arbitrary file open |
@@ -169,14 +153,24 @@ std::string read_string(pid_t pid, unsigned long reg, unsigned long length) { |
169 | 153 |
|
170 | 154 | void inspect_for_injection(pid_t pid, const user_regs_struct ®s) { |
171 | 155 | // Inspect a PID's registers for the sign of shell injection. |
172 | | - std::string path = read_string(pid, regs.rdi, kTripWire.length()); |
| 156 | + std::string path = read_null_terminated(pid, regs.rdi); |
173 | 157 | if (!path.length()) { |
174 | 158 | return; |
175 | 159 | } |
176 | 160 | debug_log("inspecting"); |
177 | 161 | if (path == kTripWire) { |
178 | 162 | report_bug(kInjectionError, pid); |
179 | 163 | } |
| 164 | + |
| 165 | + // Inspect a PID's argv for signs of argument injection |
| 166 | + for (auto i: read_argv(pid, regs.rsi)) { |
| 167 | + if (i == "--") { |
| 168 | + break; |
| 169 | + } |
| 170 | + else if (i.find(kArgumentTripWire) == 0) { |
| 171 | + report_bug(kArgumentInjectionError, pid); |
| 172 | + } |
| 173 | + } |
180 | 174 | } |
181 | 175 |
|
182 | 176 | std::string get_pathname(pid_t pid, const user_regs_struct ®s) { |
|
0 commit comments