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

Add shell support for parenthesis. #361

Closed
fe7ch opened this issue Nov 23, 2016 · 11 comments
Closed

Add shell support for parenthesis. #361

fe7ch opened this issue Nov 23, 2016 · 11 comments

Comments

@fe7ch
Copy link
Contributor

fe7ch commented Nov 23, 2016

Hajime trojan started to use () brackets during infection stage. It prevents cowrie from capturing samples.

Part of the session how it was seen by the attacker:

root@honeypot:~# cd /var; (cat .s || cp /bin/echo .s); /bin/busybox GAWOG
bash: (: command not found
cp: target `GAWOG' is not a directory
root@busybox:/var# (dd bs=52 count=1 if=.s || cat .s)
bash: (: command not found
cat: .s: No such file or directory
cat: ): No such file or directory
2016-11-23 07:01:18+0300 [CowrieTelnetTransport,951,censored] CMD: cd /var; (cat .s || cp /bin/echo .s); /bin/busybox GAWOG
2016-11-23 07:01:18+0300 [CowrieTelnetTransport,951,censored] Command found: cd /var
2016-11-23 07:01:18+0300 [CowrieTelnetTransport,951,censored] Command not found: ( cat .s
2016-11-23 07:01:18+0300 [CowrieTelnetTransport,951,censored] Command found: cp /bin/echo .s ); /bin/busybox GAWOG
2016-11-23 07:01:19+0300 [CowrieTelnetTransport,951,censored] CMD: (dd bs=52 count=1 if=.s || cat .s)
2016-11-23 07:01:19+0300 [CowrieTelnetTransport,951,censored] Command not found: ( dd bs=52 count=1 if=.s
2016-11-23 07:01:19+0300 [CowrieTelnetTransport,951,censored] Command found: cat .s )
2016-11-23 07:01:19+0300 [CowrieTelnetTransport,951,censored] CMD: /bin/busybox GAWOG
@dwasss
Copy link
Contributor

dwasss commented Nov 28, 2016

By brackets I think you mean parentheses? In any case, I have seen this on my cowrie as well.

@fe7ch fe7ch changed the title Basic support for brackets Basic support for parentheses Nov 28, 2016
@fe7ch
Copy link
Contributor Author

fe7ch commented Nov 28, 2016

By brackets I think you mean parentheses? In any case, I have seen this on my cowrie as well.

Yep, thanks. I've translated it incorrectly :(

@fe7ch
Copy link
Contributor Author

fe7ch commented Nov 28, 2016

If I got it right, shlex doesn't support parentheses. That's sad.

@micheloosterhof micheloosterhof changed the title Basic support for parentheses Add shell support for parenthesis. Dec 5, 2016
@micheloosterhof
Copy link
Member

The quick fix would be to just ignore parenthesis.

@fe7ch
Copy link
Contributor Author

fe7ch commented Dec 5, 2016

The quick fix would be to just ignore parenthesis.

Yep, that's what I did. (fe7ch@ede2338, fe7ch@e2cd464). I wasn't sure if you are okey with such dirty hacks, so I didn't fill it in pull request.

@dwasss
Copy link
Contributor

dwasss commented Dec 5, 2016

I keep seeing this on my honeypot. A fix that works would be appreciated! :)

@fe7ch
Copy link
Contributor Author

fe7ch commented Dec 6, 2016

micheloosterhof, dwasserm, I've filled a pull request with a hotfix. It was tested on my honeypots for a week or so.

@dwasss
Copy link
Contributor

dwasss commented Jan 5, 2017

Cool. Can the hotfix be merged into the current build?

@fe7ch
Copy link
Contributor Author

fe7ch commented Jan 21, 2017

Closed, since a solution was merged.

@fe7ch fe7ch closed this as completed Jan 21, 2017
@funtimes-ninja
Copy link
Contributor

@fe7ch not sure if I'm doing something incorrect or not, however I've followed the same guidance for copying a working copy of the binary's into honeyfs/bin in order to get this sample captured, however it doesn't seem to work, was hoping maybe you could shed some light on the situation

2017-02-08 17:10:51-0500 [CowrieTelnetTransport,2,14.44.103.9] CMD: (dd bs=52 count=1 if=.s || cat .s)
2017-02-08 17:10:51-0500 [CowrieTelnetTransport,2,14.44.103.9] Command not found: dd bs=52 count=1 if=.s
root@honeypot-1:/home/cowrie/cowrie/honeyfs/bin# ls -la
total 264
drwxrwxr-x 2 cowrie cowrie   4096 Feb  8 17:09 .
drwxrwxr-x 5 cowrie cowrie   4096 Feb  7 17:39 ..
-rwxr-xr-x 1 cowrie cowrie  72632 Feb  8 17:09 dd
-rwxr-xr-x 1 cowrie cowrie  31376 Feb  8 10:10 echo
-rwxr-xr-x 1 cowrie cowrie 154072 Feb  8 16:44 sh

@fe7ch
Copy link
Contributor Author

fe7ch commented Feb 9, 2017

@funtimes-ninja
I'll have more clues if you post full session log and the output of file honeyfs/bin/echo.

You don't neeed dd in honeyfs/bin since it's used as command, so it's needed to be implemented as a command (#344). But in fact, the trojan will drop the payload even if dd fails (cat .s will be executed in this case).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants