Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
L
Linux Library Inject
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Chu
Linux Library Inject
Commits
8bee9e03
Commit
8bee9e03
authored
Dec 24, 2019
by
Chu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
get_entry
parent
2d967c2f
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
66 additions
and
7 deletions
+66
-7
elf.cpp
inject/elf.cpp
+9
-1
elf.h
inject/elf.h
+3
-2
main.cpp
inject/main.cpp
+14
-3
process.cpp
inject/process.cpp
+36
-0
process.h
inject/process.h
+4
-1
No files found.
inject/elf.cpp
View file @
8bee9e03
...
...
@@ -14,7 +14,7 @@ Elf::~Elf()
munmap
(
memory_
,
memory_length_
);
}
void
Elf
::
set_base
(
unsigned
long
base
)
void
Elf
::
set_base
(
std
::
size_t
base
)
{
base_
=
base
;
}
...
...
@@ -67,3 +67,11 @@ void Elf::load_to_memory()
ehdr_
=
reinterpret_cast
<
Elf64_Ehdr
*>
(
memory_
);
shdr_
=
reinterpret_cast
<
Elf64_Shdr
*>
(
memory_
+
ehdr_
->
e_shoff
);
}
std
::
size_t
Elf
::
get_entry
()
{
if
(
!
memory_
)
load_to_memory
();
return
base_
+
ehdr_
->
e_entry
;
}
inject/elf.h
View file @
8bee9e03
...
...
@@ -11,12 +11,13 @@ class Elf final
public
:
explicit
Elf
(
std
::
string
path
)
:
path_
(
std
::
move
(
path
))
{}
~
Elf
();
void
set_base
(
unsigned
long
base
);
void
set_base
(
std
::
size_t
base
);
std
::
size_t
find_symbol_address_by_name
(
std
::
string_view
name
);
std
::
size_t
get_entry
();
private
:
std
::
string
path_
;
unsigned
long
base_
=
0
;
std
::
size_t
base_
=
0
;
std
::
size_t
memory_length_
=
0
;
unsigned
char
*
memory_
=
nullptr
;
Elf64_Ehdr
*
ehdr_
=
nullptr
;
...
...
inject/main.cpp
View file @
8bee9e03
...
...
@@ -45,19 +45,30 @@ int main(int argc, char *argv[])
// find __libc_dlopen_mode in libc.so
Elf
libc
(
libc_path
);
libc
.
set_base
(
libc_base
);
std
::
size_t
libc_dlopen_mode
_addr
;
std
::
size_t
libc_dlopen_mode
;
try
{
libc_dlopen_mode
_addr
=
libc
.
find_symbol_address_by_name
(
"__libc_dlopen_mode"
);
libc_dlopen_mode
=
libc
.
find_symbol_address_by_name
(
"__libc_dlopen_mode"
);
}
catch
(
const
std
::
exception
&
e
)
{
std
::
cerr
<<
"[!] "
<<
e
.
what
()
<<
std
::
endl
;
return
1
;
}
std
::
cout
<<
"[+] __libc_dlopen_mode: 0x"
<<
libc_dlopen_mode
_addr
<<
std
::
endl
;
std
::
cout
<<
"[+] __libc_dlopen_mode: 0x"
<<
libc_dlopen_mode
<<
std
::
endl
;
// get process' entry
std
::
size_t
entry
;
try
{
entry
=
process
.
get_entry
();
}
catch
(
const
std
::
exception
&
e
)
{
std
::
cerr
<<
"[!] "
<<
e
.
what
()
<<
std
::
endl
;
return
1
;
}
std
::
cout
<<
"[+] entry: 0x"
<<
entry
<<
std
::
endl
;
// copy shellcode to process' entry
...
...
inject/process.cpp
View file @
8bee9e03
#include "process.h"
#include <unistd.h>
#include <cstring>
#include <fstream>
#include <regex>
#include "elf.h"
std
::
pair
<
std
::
string
,
std
::
size_t
>
Process
::
find_libc
()
{
std
::
string
filename
(
"/proc/"
);
...
...
@@ -21,3 +26,34 @@ std::pair<std::string, std::size_t> Process::find_libc()
throw
std
::
runtime_error
(
"libc.so not found in "
+
filename
);
}
std
::
size_t
Process
::
get_base
()
{
std
::
string
filename
(
"/proc/"
);
filename
+=
std
::
to_string
(
pid_
);
filename
+=
"/maps"
;
std
::
ifstream
file
(
filename
);
std
::
string
line
;
file
>>
line
;
return
std
::
stoul
(
line
,
nullptr
,
16
);
}
std
::
string
Process
::
get_execute
()
{
std
::
string
filename
(
"/proc/"
);
filename
+=
std
::
to_string
(
pid_
);
filename
+=
"/exe"
;
char
execute
[
1024
]
=
{
0
};
if
(
readlink
(
filename
.
c_str
(),
execute
,
1023
)
!=
-
1
)
return
execute
;
throw
std
::
runtime_error
(
std
::
strerror
(
errno
));
}
std
::
size_t
Process
::
get_entry
()
{
auto
execute
=
get_execute
();
Elf
elf
(
execute
);
elf
.
set_base
(
get_base
());
return
elf
.
get_entry
();
}
inject/process.h
View file @
8bee9e03
...
...
@@ -10,11 +10,14 @@ class Process final
{
public
:
explicit
Process
(
pid_t
pid
)
:
pid_
(
pid
)
{}
std
::
pair
<
std
::
string
,
std
::
size_t
>
find_libc
();
std
::
size_t
get_entry
();
private
:
pid_t
pid_
;
std
::
size_t
get_base
();
std
::
string
get_execute
();
};
#endif // LINUX_LIBRARY_INJECT_PROCESS_H
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment