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
67189f6e
Commit
67189f6e
authored
Dec 24, 2019
by
Chu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
remove exception
parent
f69ba366
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
13 additions
and
50 deletions
+13
-50
elf.cpp
inject/elf.cpp
+4
-1
main.cpp
inject/main.cpp
+9
-49
No files found.
inject/elf.cpp
View file @
67189f6e
...
...
@@ -6,6 +6,7 @@
#include <unistd.h>
#include <cstring>
#include <sstream>
#include <stdexcept>
Elf
::~
Elf
()
...
...
@@ -95,5 +96,7 @@ std::size_t Elf::get_func_size(std::size_t address)
}
}
throw
std
::
runtime_error
(
std
::
to_string
(
address
)
+
" not found in "
+
path_
);
std
::
ostringstream
stream
;
stream
<<
"0x"
<<
std
::
hex
<<
address
<<
" not found in "
<<
path_
;
throw
std
::
runtime_error
(
stream
.
str
());
}
inject/main.cpp
View file @
67189f6e
#include <sys/types.h>
#include <iostream>
#include <string>
#include <tuple>
#include "elf.h"
#include "process.h"
...
...
@@ -18,65 +15,28 @@ int main(int argc, char *argv[])
}
// process
pid_t
pid
=
0
;
try
{
pid
=
std
::
stoi
(
argv
[
1
]);
}
catch
(
const
std
::
exception
&
)
{
std
::
cerr
<<
"[!] invalid pid "
<<
argv
[
1
]
<<
std
::
endl
;
return
1
;
}
Process
process
(
pid
);
Process
process
(
std
::
stoi
(
argv
[
1
]));
// find libc.so in process
std
::
string
libc_path
;
std
::
size_t
libc_base
;
try
{
std
::
tie
(
libc_path
,
libc_base
)
=
process
.
find_libc
();
}
catch
(
const
std
::
exception
&
e
)
{
std
::
cerr
<<
"[!] "
<<
e
.
what
()
<<
std
::
endl
;
return
1
;
}
auto
[
libc_path
,
libc_base
]
=
process
.
find_libc
();
std
::
cout
<<
"[+] libc: "
<<
libc_path
<<
" 0x"
<<
std
::
hex
<<
libc_base
<<
std
::
endl
;
// find __libc_dlopen_mode in libc.so
Elf
libc
(
libc_path
);
libc
.
set_base
(
libc_base
);
std
::
size_t
libc_dlopen_mode
;
try
{
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
;
}
auto
libc_dlopen_mode
=
libc
.
find_symbol_address_by_name
(
"__libc_dlopen_mode"
);
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
;
}
auto
entry
=
process
.
get_entry
();
std
::
cout
<<
"[+] entry: 0x"
<<
entry
<<
std
::
endl
;
// copy shellcode to process' entry
auto
call_libc_dlopen_mode_addr
=
reinterpret_cast
<
std
::
size_t
>
(
&
call_libc_dlopen_mode
);
auto
call_libc_dlopen_mode_size
=
Elf
(
argv
[
0
]).
get_func_size
(
call_libc_dlopen_mode_addr
);
std
::
cout
<<
"[+] shellcode: 0x"
<<
call_libc_dlopen_mode_addr
<<
" "
<<
std
::
dec
<<
call_libc_dlopen_mode_size
<<
std
::
endl
;
auto
call_libc_dlopen_mode_addr
=
&
call_libc_dlopen_mode
;
auto
call_libc_dlopen_mode_size
=
Elf
(
argv
[
0
]).
get_func_size
(
reinterpret_cast
<
std
::
size_t
>
(
call_libc_dlopen_mode_addr
));
std
::
cout
<<
"[+] shellcode: 0x"
<<
reinterpret_cast
<
std
::
size_t
>
(
call_libc_dlopen_mode_addr
)
<<
" "
<<
std
::
dec
<<
call_libc_dlopen_mode_size
<<
std
::
endl
;
// call shellcode
...
...
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