Skip to content
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

Simple Hello-World BOF crashes beacon #794

Closed
1mansh0w opened this issue Aug 22, 2022 · 16 comments · Fixed by #797
Closed

Simple Hello-World BOF crashes beacon #794

1mansh0w opened this issue Aug 22, 2022 · 16 comments · Fixed by #797
Labels
bug Something isn't working duplicate This issue or pull request already exists investigating

Comments

@1mansh0w
Copy link

1mansh0w commented Aug 22, 2022

I'm having issues creating a simple BOF that does not crash the beacon.

Here is the source code:
/~https://github.com/1mansh0w/sliver-bof-hello-world

Here is how I load it:

1. extensions rm say-hello
2. extensions load "[path]/hello_world"
3. extensions install "[path]/hello_world"  

When I now execute the BOF only once it always runs fine, but executing it a couple of more times will always crash the beacon. The client will just show this message and the session is lost:

"Executing say-hello ..."

Am I doing something wrong or is there a bug in sliver?

Thanks!


I'm running the latest version of Sliver (v1.5.22) on both client and server. I'm cross-compiling the BOF on Ubuntu.

@rkervella
Copy link
Member

Are you running a beacon or a session?

@1mansh0w
Copy link
Author

1mansh0w commented Aug 22, 2022

Hey @rkervella, thanks for looking into it!

I'm running a session. Maybe it is related to: #679

To clarify a little bit more: If I just run the BOF once on a session it works without problems. But if I execute it multiple times (right after another) the session crashes.

@rkervella
Copy link
Member

Yup I've seen that happens with other BOFs, as stated in #679. I'll have a look. I looked at your BOF, it seems fine so it's definitely a bug on our side.

@rkervella
Copy link
Member

The annoying part is I can't seem to be able to reproduce:

[server] sliver (TIRED_BUSTLE) > say-hello

[*] Successfully executed say-hello (coff-loader)
[*] Got output:
Hello World
[server] sliver (TIRED_BUSTLE) > say-hello

[*] Successfully executed say-hello (coff-loader)
[*] Got output:
Hello World

[server] sliver (TIRED_BUSTLE) > say-hello

[*] Successfully executed say-hello (coff-loader)
[*] Got output:
Hello World

[server] sliver (TIRED_BUSTLE) > say-hello

[*] Successfully executed say-hello (coff-loader)
[*] Got output:
Hello World

[server] sliver (TIRED_BUSTLE) > say-hello
[server] sliver (TIRED_BUSTLE) > say-hello

[*] Successfully executed say-hello (coff-loader)
[*] Got output:
Hello World

[server] sliver (TIRED_BUSTLE) > say-hello

[*] Successfully executed say-hello (coff-loader)
[*] Got output:
Hello World

[server] sliver (TIRED_BUSTLE) > say-hello

[*] Successfully executed say-hello (coff-loader)
[*] Got output:
Hello World

[server] sliver (TIRED_BUSTLE) > say-hello

[*] Successfully executed say-hello (coff-loader)
[*] Got output:
Hello World

@rkervella rkervella added bug Something isn't working duplicate This issue or pull request already exists labels Aug 22, 2022
@1mansh0w
Copy link
Author

1mansh0w commented Aug 22, 2022

Interesting... You have used my Makefile with mingw I guess?

Is there any information/log when executing BOFs? Like a stack trace or any information that helps debugging once a session/beacon crashes?

@rkervella
Copy link
Member

Yes, if you generate your implant with --debug, and run it from a terminal, you should be able to see the crash.

@r00t0v3rr1d3
Copy link
Contributor

sa-uptime and sa-resources when in beacon mode are consistent in eventually crashing for me

@rkervella
Copy link
Member

rkervella commented Aug 22, 2022

sa-uptime and sa-resources when in beacon mode are consistent in eventually crashing for me

Only in beacon mode though?

@r00t0v3rr1d3
Copy link
Contributor

For me, MOST of the instability / crashing seems to go away in session mode. Occasionally I can get those same BOFs to hang forever in session mode if I up arrow + enter really fast.

@moloch--
Copy link
Member

Hurm, i wonder if its some race condition in the invocation?

@rkervella
Copy link
Member

Yeah definitely looks like it

@1mansh0w
Copy link
Author

1mansh0w commented Aug 22, 2022

What's really weird now is that since I have created an implant with --debug, it doesn't crash anymore. I can neither crash my say-hello BOF nor sa-uptime:

Screen Shot 2022-08-22 at 18 56 33

So I thought there was an issue with the old implant, but when I created a new implant (v1.5.22) without --debug, I can get it crashing again:

Screen Shot 2022-08-22 at 18 25 33

Screen Shot 2022-08-22 at 18 51 23

I didn't look into the code yet to see whether the debug flag really contributes to the issue.
@r00t0v3rr1d3 Do you see any difference when you build an implant with the debug flag?

@rkervella
Copy link
Member

Hm that's good to know. I'll run more tests with obfuscation enabled, see if crashes. If so, it could also be an issue with garble.

@r00t0v3rr1d3
Copy link
Contributor

I haven’t tried recently to build one using the —debug flag. Not with Golang, but with C - I’ve definitely seen things where the debug version magically saved crashes from happening that the exact same code in “release” form would cause it to fall on its face.

@rkervella
Copy link
Member

Alright I can reproduce with obfuscation enabled.

@rkervella
Copy link
Member

Alright it was indeed a race condition, PR #797 should fix this one and #679 .

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working duplicate This issue or pull request already exists investigating
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants