Heim  >  Artikel  >  Datenbank  >  自定义的Oracle用户密码效验程序

自定义的Oracle用户密码效验程序

WBOY
WBOYOriginal
2016-06-07 17:35:49867Durchsuche

Oracle的verify_function_11G函数只是通过一些密码规则来让密码看起来不容易猜到,但一些用户的习惯让所设的密码虽然复杂,但并不

Oracle的verify_function_11G函数只是通过一些密码规则来让密码看起来不容易猜到,但一些用户的习惯让所设的密码虽然复杂,但并不难猜,这时可以用我写的这个程序,把一些常见的易猜的密码放入文件或字典数据库中, 通过程序自动尝试连接Oracle数据库,来效验指定数据密码是否太过易猜或简单,如果数据库用户配置稍严格些,这个程序就不起作用了,所以不太具有实用价值,仅参考使用。

程序用到了 SQLite与 OTL可看:  SQLite编程相关()      OTL的使用() 去了解相关使用方法。

程序代码如下:

/**
* author: xiongchuanliang
* desc: 效验密码是否是使用数据库默认密码,或密码是否太过简单
      程序的参数说明:
        -d 效验是否使用默认用户和密码没改过
  -s 事先在SQLite数据库中存放各类数据库密码,然后依次尝试。
      可通过 “ -s a% “这类来从字典表中过滤出相符合的密码字符串
  -f 从密码文件中读取密码字符串依次尝试
*/

#include
#include
#include
#include

#include "sqlite3.h"


#define OTL_ORA10G
//#define OTL_ORA11G_R2 // Compile OTL 4.0/OCI11.2
#include "otlv4.h" // include the OTL 4 header file

using namespace std;
otl_connect oracledb;

#define MAXLINE 150

#define DICT_DB  "c:\\sqlite\\mydict.db"
#define DICT_FILE "c:/sqlite/mydict.txt"
#define TNS_DBNAME "xcldb"

#define SQL_COUNT  " SELECT count(*) FROM userpwd "
#define SQL_SELECT  " SELECT pwd FROM userpwd "

char arrTestUser[][30] = {"sys","system","test"};
int arrTestUserLen = 3;


//从SQLite只按条件查出密码串放入文件
sqlite3_uint64 getDictDB(char * pWhere);

//初始化OTL
void initOTL();

//连接Oracle数据库
int connectORA(char * connstr);

//从字典文件读入密码字符串尝试连接
bool testConnDB();

//尝试用默认的用户名和密码连接
bool testConnDBDF();

int main(int argc, char* argv[])
{
 printf("==========================\n");
 printf("数据库密码有效性测试!\n");
 printf("==========================\n");

 if(argc==1||argc    printf("请输入运行参数(-f,-d,-s).\n");
   
 //从指定字典文件中查找
 if( strcmp(argv[1],"-f") == 0)
 {
  printf(" -f : 从指定字典文件中查找\n");
  testConnDB();
 }else{

   initOTL();
   //查数据库默认用户密码 
   if( strcmp(argv[1],"-d") == 0)
   {
    printf(" -d : 查数据库默认用户密码 \n");
    testConnDBDF();
   }else if( strcmp(argv[1],"-s") == 0) //从SQLite数据库找出密码
   {

    printf(" -s : 从SQLite数据库找出密码 \n"); 
    if(argc==3)
    {
      printf("过滤条件: %s\n",argv[2]); // %a123%
      char sW[50] = {0};
      //char *s = " where pwd like '%aaa%' ";
      sprintf_s(sW, " where pwd like '%s' ",argv[2]);
      getDictDB(sW);
    }else{
      char *sW = NULL;
      getDictDB(sW);
    }     
    //从数据库中转出的密码文件中读取密码进行尝试
    testConnDB();
   }else{
    printf("请输入(-f,-d,-s)三个参数之一.\n");
   }
 }
 
 return 0;
}

//从SQLite只按条件查出密码串放入文件
sqlite3_uint64 getDictDB(char * pWhere)

 char sqlCount[MAXLINE] = {0};
 char sqlSelect[MAXLINE] = {0}; 

 strcpy_s(sqlCount,SQL_COUNT);
 strcpy_s(sqlSelect,SQL_SELECT);

 if(pWhere != NULL)
 {
  strcat_s(sqlCount,pWhere);
    strcat_s(sqlSelect,pWhere);
 }

 sqlite3 * pDB = NULL;

 //打开路径采用utf-8编码 
    //如果路径中包含中文,,需要进行编码转换 
 // c:\\sqlite\\mydict.db
    int nRes = sqlite3_open(DICT_DB, &pDB); 
    if (nRes != SQLITE_OK) 
    {   
  printf("字典数据库连接失败. %s \n",sqlite3_errmsg(pDB)); 
  return 0;
    } 

 sqlite3_stmt * stmt;
    const char *pTail;    
 sqlite3_uint64 rCount = 0;
 int rc = 0;

 //查询所有数据
    sqlite3_prepare(pDB, sqlCount,-1,&stmt,&pTail);
    int r = sqlite3_step(stmt);               
 if(r == SQLITE_ROW)
 {
    rCount = sqlite3_column_int64( stmt, 0 );  
    printf("共找到%d条字典密码.\n",rCount);
 }
 sqlite3_finalize(stmt);
 
 if(rCount

 //查询所有数据
    sqlite3_prepare(pDB, sqlSelect,-1,&stmt,&pTail);

 
 do{ 

  FILE *fp;
  fopen_s(&fp,DICT_FILE,"w");
  if(fp == NULL)
  {
   printf("字典文件生成失败.\n");
   goto end;
  }

Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn