dinhanhx / dinhanhx/dove-shell
🔒 Security: pickle.loads on untrusted data enables remote code execution
- Dominant language
- Python
- Stars
- 0
- Forks
- 0
- PR merge metrics
- No merged PRs in 30d
Description
## Description
In `dove-shell/security.py` line 43:
```python
from pickle import dumps, loads
def decrypt_decode(bundle: bytes, private_key: RSA.RsaKey):
session_key, nonce, tag, encrypted_cmd = loads(bundle) # DANGEROUS
```
And in `encode_encrypt()` (line 27):
```python
bundle = (encrypted_session_key, cipher_AES.nonce, tag, encrypted_cmd)
return dumps(bundle)
```
`pickle.loads()` is used to deserialize network data. If an attacker can send crafted pickle data, they can achieve **arbitrary code execution** on the receiving end. Even though the data is encrypted, this is defense-in-depth: if keys are compromised, pickle becomes an RCE vector.
### Also: File handles never closed (`security.py`, lines 66-67)
```python
private_key = RSA.import_key(open(private_key_file, 'r').read())
public_key = RSA.import_key(open(public_key_file, 'r').read())
```
Files are opened but never closed. Should use `with` statements.
### Also: Arbitrary command execution without any sanitization (`dove_shell.py`, line 73)
```python
output = subprocess.getoutput(cmd)
```
Any command received from the client is executed without validation. This is by design (it's a remote shell), but there's no authentication, no session management, and no command allowlist.
## Suggested Fix
Replace pickle with a simple struct or JSON encoding:
```python
import struct
# Pack: key_len(4) + key + nonce(16) + tag(16) + ciphertext
```
Contributor guide
No contributing guide indexed for this repository
Research direction
The affected entry points are encode_encrypt() and decrypt_decode() in dove-shell/security.py, plus key loading at lines 66-67 and subprocess.getoutput() in dove_shell.py line 73. Read these paths first; done means the network bundle no longer uses pickle, key files are closed, and the authentication, session-management, and command-validation concerns are addressed or explicitly scoped.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- security
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100