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

UnicodeDecodeError when calling aggressor.artifact_payload #8

Open
oldloco opened this issue Jun 21, 2021 · 0 comments
Open

UnicodeDecodeError when calling aggressor.artifact_payload #8

oldloco opened this issue Jun 21, 2021 · 0 comments

Comments

@oldloco
Copy link

oldloco commented Jun 21, 2021

Hello,

I have this small script that should create x64 executable called beacon.exe, when create-executable alias is called:

import pycobalt.engine as engine
import pycobalt.events as events                                                                                   
import pycobalt.aliases as aliases                                                                                 
import pycobalt.helpers as helpers                                                                                 
import pycobalt.commands as commands                                                                               
import pycobalt.aggressor as aggressor                                                                             
import pycobalt.callbacks as callbacks                                                                             
import pycobalt.console as console                                                                                  
                                                                                                                                             
@aliases.alias("create-executable", "Creates executable")                                                                                    
def _(bid, listener):                                                                                                                        
    executable = aggressor.artifact_payload(listener, "exe", "x64")                                                                          
    local_path = "/tmp/beacon.exe"                                                                                                           
    f = open(local_path, "wb")                                                                                                               
    f.write(executable)                                                                                                                      
    f.close()                                                                                                                                
                                                                                                                                             
engine.loop()

When I call this alias in beacon console, I get this error in Script Console:

[pycobalt] Executing script /tmp/beacon.py
[pycobalt beacon.py error] Traceback (most recent call last):
[pycobalt beacon.py error]   File "/tmp/beacon.py", line 18, in <module>
[pycobalt beacon.py error]     engine.loop()
[pycobalt beacon.py error]   File "/usr/local/lib/python3.9/dist-packages/pycobalt-1.2.0-py3.9.egg/pycobalt/engine.py", line 216, in loop
[pycobalt beacon.py error]     for name, message in read_pipe_iter():
[pycobalt beacon.py error]   File "/usr/local/lib/python3.9/dist-packages/pycobalt-1.2.0-py3.9.egg/pycobalt/engine.py", line 200, in read_pipe_iter
[pycobalt beacon.py error]     for line in _in_pipe:
[pycobalt beacon.py error]   File "/usr/lib/python3.9/codecs.py", line 322, in decode
[pycobalt beacon.py error]     (result, consumed) = self._buffer_decode(data, self.errors, final)
[pycobalt beacon.py error] UnicodeDecodeError: 'utf-8' codec can't decode byte 0xc0 in position 1: invalid start byte
[pycobalt] Script process exited: /tmp/beacon.py

I think it has something to do with aggressor.artifact_payload, since this same issue also arises when calling aggressor.artifact_stager.

So far I have been able to fix this error by adding sys.stdin.reconfigure(encoding="latin-1") to pycobalt/engine.py after imports and changing line 12 from my script to executable = bytes(aggressor.artifact_payload(listener, "exe", "x64"), "latin-1").

I wonder if this a proper way to fix this error or may the change to engine.py break something else?

Related version information:

  • Cobalt Strike version: 4.3.0
  • Pycobalt version: 1.2.0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant