{"id":614,"date":"2020-02-04T22:25:45","date_gmt":"2020-02-04T21:25:45","guid":{"rendered":"https:\/\/privat.andreas-klingler.de\/itsec\/?p=614"},"modified":"2026-06-10T16:32:47","modified_gmt":"2026-06-10T14:32:47","slug":"python","status":"publish","type":"post","link":"https:\/\/infosec.andreas-klingler.de\/?p=614","title":{"rendered":"Python"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">Con\u00advert a Python2 script into a Python3 script:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">2to3 -w example.py<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Fix tab\/space\/identation problems:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">autopep8 -i linuxprivchecker.py<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">If a library is installed, but can\u00adnot&nbsp;found<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">from smb.SMBConnection import SMBConnection<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">then try to search the file local\u00adly and include the path manually:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">import sys<br>sys.path.append(\"path\/to\/your\/file\")<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">One\u00adlin\u00ader for exe\u00adcut\u00ading bash in a&nbsp;file:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">echo 'import os;os.system(\"\/bin\/bash\")' &gt; \/tmp\/e.py<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Exe\u00adcute something:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">import os<br>os.system('ls -l')<br><br>__import__('os').popen('whoami').read();<br><br>os = globals()['os']<br>print(os.name)<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Use python scripts under Windows<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">If an exploit is avail\u00adable in Python, but the tar\u00adget sys\u00adtem does\u00adn\u2019t have a python instal\u00adla\u00adtion, use in anoth\u00ader Win\u00addows System\/<span class=\"caps\">VM<\/span> PyIn\u00adstaller to cre\u00adate a <span class=\"caps\">EXE<\/span> out of a Python script. Example<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"># pyinstaller --onefile windows-exploit-suggester.py<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Or use https:\/\/pypi.org\/project\/auto-py-to-exe\/<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Note: In case of an error, try a new\u00ader release (<code>pip install https:\/\/github.com\/pyinstaller\/pyinstaller\/archive\/develop.tar.gz<\/code>)<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Interpolation<\/h2>\n\n\n\n<pre class=\"wp-block-preformatted\">\"{name}\".format(name=\"P\")<br>\"%s and %d\" % (\"string\", 42)<br>f\"User {user}\" # variable user was defined before.<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Jinja Template hijacking<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\"><a href=\"https:\/\/infosec.andreas-klingler.de\/?p=4990\" data-type=\"post\" data-id=\"4990\">See Jin\u00adja article<\/a><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Flask<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Flask uses a secret key to sign cook\u00adies. If you have a secret key, you can use flask-unsign to decode a cook\u00adie you\u2019ve got from the http response.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"209\" src=\"https:\/\/andreas-klingler.de\/infosec\/wp-content\/uploads\/2020\/02\/grafik-1024x209.png\" alt class=\"wp-image-4880\" srcset=\"https:\/\/infosec.andreas-klingler.de\/wp-content\/uploads\/2020\/02\/grafik-1024x209.png 1024w, https:\/\/infosec.andreas-klingler.de\/wp-content\/uploads\/2020\/02\/grafik-300x61.png 300w, https:\/\/infosec.andreas-klingler.de\/wp-content\/uploads\/2020\/02\/grafik-768x157.png 768w, https:\/\/infosec.andreas-klingler.de\/wp-content\/uploads\/2020\/02\/grafik.png 1207w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\"><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">The sec\u00adond com\u00admand from this screen\u00adshot changed the id. The new cre\u00adat\u00aded cook\u00adie can be used for a <span class=\"caps\">HTTP<\/span> request which then would imper\u00adsion\u00adate the user with id&nbsp;20093.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Con\u00advert a Python2 script into a Python3 script: 2to3 \u2011w example.py Fix tab\/space\/identation prob\u00adlems: autopep8 \u2011i linuxprivchecker.py If a library is installed, but can\u00adnot&nbsp;found from smb.SMBConnection import SMB\u00adCon\u00adnec\u00adtion then try to search the file local\u00adly and include the path man\u00adu\u00adal\u00adly: import syssys.path.append(\u201cpath\/to\/your\/file\u201d) One\u00adlin\u00ader for exe\u00adcut\u00ading bash in a&nbsp;file: echo \u2018import os;os.system(\u201c\/bin\/bash\u201d)\u2019 &gt; \/tmp\/e.py Exe\u00adcute something:&nbsp;[\u2026]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"wp_typography_post_enhancements_disabled":false,"footnotes":""},"categories":[468],"tags":[290,178,291],"class_list":["post-614","post","type-post","status-publish","format-standard","hentry","category-general","tag-jinja","tag-python","tag-ssti"],"_links":{"self":[{"href":"https:\/\/infosec.andreas-klingler.de\/index.php?rest_route=\/wp\/v2\/posts\/614","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/infosec.andreas-klingler.de\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/infosec.andreas-klingler.de\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/infosec.andreas-klingler.de\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/infosec.andreas-klingler.de\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=614"}],"version-history":[{"count":17,"href":"https:\/\/infosec.andreas-klingler.de\/index.php?rest_route=\/wp\/v2\/posts\/614\/revisions"}],"predecessor-version":[{"id":4992,"href":"https:\/\/infosec.andreas-klingler.de\/index.php?rest_route=\/wp\/v2\/posts\/614\/revisions\/4992"}],"wp:attachment":[{"href":"https:\/\/infosec.andreas-klingler.de\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=614"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/infosec.andreas-klingler.de\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=614"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/infosec.andreas-klingler.de\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=614"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}