Advertisement
Guest User

Untitled

a guest
Jul 30th, 2017
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 14.72 KB | None | 0 0
  1. #!/usr/bin/perl -w
  2.  
  3. # Generate passwords using the following techniques:
  4. # 1. gecos based
  5. # 2. word
  6. # 3. reversed word
  7. # 4. word based (mixed case)
  8. # 5. word based with number at end
  9. # 6. word based with special characters at front and back
  10. # 7. reversed word based with special characters at front and back
  11. # 8. keyboard based
  12. # 9. word based with special character replacement
  13. # 10. word based with 2 extra symbols in the middle
  14. # 11. word based with extra symbol and special character replacement
  15. # 12. 5 random alphanumeric characters
  16. # 13. 8 random alphanumeric characters
  17. # 14. 6 random lower case alphabetic characters
  18. # 15. 7 random lower case alphabetic characters
  19. # 16. 8 lower case alphabetic characters randomly choosen from the
  20. # following three sets which have the indicated probabilities
  21. # of being choosen:
  22. #
  23. # @ascii1 {asdfghjkl} .7
  24. # @ascii2 {ertyuicvbnm} .29
  25. # @ascii3 {qwzxop} .01
  26. # 17. The above (16) is modified by choosing two characters from
  27. # the machine name tyro, keeping them in the same order and
  28. # inserting them in the interior (not at front or end) of 6
  29. # characters choosen as in 16.
  30. #
  31. # Three files are required in the current directory
  32. # 1. ./students - list of ringer logins - one/line
  33. # 2. ./nisfile - some type of password files through gcos field
  34. # 3. ./words.linux - dictionary of words on which to base passwords
  35. #
  36.  
  37. %keyb = ( '1' , '2q',
  38. '2' , '1qw3',
  39. '3' , '2we4',
  40. '4' , '3er5',
  41. '5' , '4rt6',
  42. '6' , '5ty7',
  43. '7' , '6yu8',
  44. '8' , '7ui9',
  45. '9' , '8io0',
  46. '0' , '9op-',
  47. '-' , '0p=',
  48. '=' , '-',
  49. 'q' , '12wa',
  50. 'w' , '2qase3',
  51. 'e' , '3wsdr4',
  52. 'r' , '4edft5',
  53. 't' , '5rfgy6',
  54. 'y' , '6tghu7',
  55. 'u' , '7yhji8',
  56. 'i' , '8ujko9',
  57. 'o' , '9iklp0',
  58. 'p' , '0ol;-',
  59. 'a' , 'zswq',
  60. 's' , 'wazxde',
  61. 'd' , 'esxcfr',
  62. 'f' , 'rdcvgt',
  63. 'g' , 'tfvbhy',
  64. 'h' , 'ygbnju',
  65. 'j' , 'uhnmki',
  66. 'k' , 'ijm,lo',
  67. 'l' , 'ok,.;p',
  68. ';' , 'pl./',
  69. 'z' , 'axs',
  70. 'x' , 'szcd',
  71. 'c' , 'dxvf',
  72. 'v' , 'fcbg',
  73. 'b' , 'gvnh',
  74. 'n' , 'hbmj',
  75. 'm' , 'jn,k',
  76. ',' , 'km.l',
  77. '.' , 'l,/;',
  78. '/' , ';.'
  79. );
  80.  
  81. %equiv = ( 'a' , '@',
  82. 'A' , '@',
  83. 'c' , '(',
  84. 'C' , '(',
  85. 'd' , '.',
  86. 'D' , '.',
  87. 'i' , '!',
  88. 'I' , '!',
  89. 'l' , '|',
  90. 'L' , '|',
  91. 'o' , '0',
  92. 'O' , '0',
  93. 'v' , '^',
  94. 'V' , '^',
  95. 'n' , '#',
  96. 'N' , '#',
  97. 's' , '$',
  98. 'S' , '$'
  99. );
  100.  
  101. @sym = ('~','`','!','@','#','$','%','^','&','*','_','-',' ','=','|',':','?','/','.','>','<',',');
  102. @ascii = (0..9,'A'..'Z','a'..'z');
  103. @lcascii = ('a'..'z');
  104. @ascii1 = ('a','s','d','f','g','h','j','k','l');
  105. @ascii2 = ('e','r','t','y','u','i','c','v','b','n','m');
  106. @ascii3 = ('q','w','z','x','o','p');
  107. @mname = ('t','y','r','o');
  108.  
  109. $students = "./students";
  110. $users = "./nisfile";
  111. #$words = "/usr/dict/words";
  112. $words = "words.linux";
  113.  
  114. @students = `cat $students`;
  115. chop @students;
  116.  
  117. @users = `cat $users`;
  118. chop @users;
  119.  
  120. @words = `cat $words`;
  121. chop @words;
  122.  
  123. foreach $student (@students) {
  124. open(PASS,">passwd.$student.pw") or warn "Unable to open passwd.$student:$!\n";
  125. open(CLEAR,">passwd.$student.clear") or warn "Unable to open passwd.$student.clear:$!\n";
  126. undef %pwusers;
  127.  
  128. # 1. gecos based
  129. do {
  130. @fields = split(/:/,$users[int(rand @users)]);
  131. } while ( !$fields[4] );
  132. $pwusers{$fields[0]} = 1;
  133. $salt = join '', ('.', '/', 0..9, 'A'..'Z', 'a'..'z')[int(rand 64),int(rand 64)];
  134. @name = split(/ /,$fields[4]);
  135. $pw = $name[$#name];
  136. $pw = substr($pw,0,8);
  137. $fields[1] = crypt($pw,$salt);
  138. $#fields -= 1;
  139. print PASS join(":",@fields),"\n";
  140. print CLEAR "$fields[0]:$pw\n";
  141.  
  142. # 2. word (all lower case)
  143. do {
  144. @fields = split(/:/,$users[int(rand @users)]);
  145. } while ( exists $pwusers{$fields[0]} );
  146. $pwusers{$fields[0]} = 1;
  147. $salt = join '', ('.', '/', 0..9, 'A'..'Z', 'a'..'z')[int(rand 64),int(rand 64)];
  148. $word = baseword();
  149. $word = substr($word,0,8);
  150. $fields[1] = crypt($word,$salt);
  151. $#fields -= 1;
  152. print PASS join(":",@fields),"\n";
  153. print CLEAR "$fields[0]:$word\n";
  154.  
  155.  
  156. # 3. reverse word (all lower case)
  157. do {
  158. @fields = split(/:/,$users[int(rand @users)]);
  159. } while ( exists $pwusers{$fields[0]} );
  160. $pwusers{$fields[0]} = 1;
  161. $salt = join '', ('.', '/', 0..9, 'A'..'Z', 'a'..'z')[int(rand 64),int(rand 64)];
  162. $word = baseword();
  163. $word = substr($word,0,8);
  164. @letters = split(//,$word);
  165. @letters = reverse(@letters);
  166. $word = join('',@letters);
  167. $fields[1] = crypt($word,$salt);
  168. $#fields -= 1;
  169. print PASS join(":",@fields),"\n";
  170. print CLEAR "$fields[0]:$word\n";
  171.  
  172. # 4. word based (mixed case)
  173. do {
  174. @fields = split(/:/,$users[int(rand @users)]);
  175. } while ( exists $pwusers{$fields[0]} );
  176. $pwusers{$fields[0]} = 1;
  177. $salt = join '', ('.', '/', 0..9, 'A'..'Z', 'a'..'z')[int(rand 64),int(rand 64)];
  178. $word = baseword();
  179. $word = substr($word,0,8);
  180. @letters = split(//,$word);
  181. foreach $c (@letters) {
  182. if ( int(rand 2) ) {
  183. $c = uc $c;
  184. } else {
  185. $c = lc $c;
  186. }
  187. }
  188. $pw = join("",@letters);
  189. $fields[1] = crypt($pw,$salt);
  190. $#fields -= 1;
  191. print PASS join(":",@fields),"\n";
  192. print CLEAR "$fields[0]:$pw\n";
  193.  
  194. # 5. word based with number at back
  195. do {
  196. @fields = split(/:/,$users[int(rand @users)]);
  197. } while ( exists $pwusers{$fields[0]} );
  198. $pwusers{$fields[0]} = 1;
  199. $salt = join '', ('.', '/', 0..9, 'A'..'Z', 'a'..'z')[int(rand 64),int(rand 64)];
  200. $word = baseword();
  201. $word = substr($word,0,7);
  202. $pw = $word . int rand(10);
  203. $fields[1] = crypt($pw,$salt);
  204. $#fields -= 1;
  205. print PASS join(":",@fields),"\n";
  206. print CLEAR "$fields[0]:$pw\n";
  207.  
  208. # 6. word based with special characters at front and back
  209. do {
  210. @fields = split(/:/,$users[int(rand @users)]);
  211. } while ( exists $pwusers{$fields[0]} );
  212. $pwusers{$fields[0]} = 1;
  213. $salt = join '', ('.', '/', 0..9, 'A'..'Z', 'a'..'z')[int(rand 64),int(rand 64)];
  214. $word = baseword();
  215. $word = substr($word,0,6);
  216. $pw = $sym[int(rand @sym)] . $word . $sym[int(rand @sym)];
  217. $fields[1] = crypt($pw,$salt);
  218. $#fields -= 1;
  219. print PASS join(":",@fields),"\n";
  220. print CLEAR "$fields[0]:$pw\n";
  221.  
  222. # 7. reversed word based with special characters at front and back
  223. do {
  224. @fields = split(/:/,$users[int(rand @users)]);
  225. } while ( exists $pwusers{$fields[0]} );
  226. $pwusers{$fields[0]} = 1;
  227. $salt = join '', ('.', '/', 0..9, 'A'..'Z', 'a'..'z')[int(rand 64),int(rand 64)];
  228. $word = baseword();
  229. $word = substr($word,0,6);
  230. @letters = split(//,$word);
  231. @letters = reverse @letters;
  232. $pw = join("",@letters);
  233. $pw = $sym[int(rand @sym)] . $pw . $sym[int(rand @sym)];
  234. $fields[1] = crypt($pw,$salt);
  235. $#fields -= 1;
  236. print PASS join(":",@fields),"\n";
  237. print CLEAR "$fields[0]:$pw\n";
  238.  
  239. # 8. keyboard based
  240. do {
  241. @fields = split(/:/,$users[int(rand @users)]);
  242. } while ( exists $pwusers{$fields[0]} );
  243. $pwusers{$fields[0]} = 1;
  244. $salt = join '', ('.', '/', 0..9, 'A'..'Z', 'a'..'z')[int(rand 64),int(rand 64)];
  245. @keys = keys(%keyb);
  246. $pw = $keys[int(rand @keys)];
  247. $prev = $pw;
  248. $nbh = $keyb{$pw};
  249. @nbhs = split(//,$nbh);
  250. $let = $nbhs[int(rand @nbhs)];
  251. $pw .= $let;
  252. $cur = $let;
  253. for($i=2; $i<8; $i ) {
  254. $nbh = $keyb{$cur};
  255. @nbhs = split(//,$nbh);
  256. do {
  257. $let = $nbhs[int(rand @nbhs)];
  258. } while ( $let eq $prev && $cur ne '=' );
  259. $pw .= $let;
  260. $prev = $cur;
  261. $cur = $let;
  262. }
  263. $fields[1] = crypt($pw,$salt);
  264. $#fields -= 1;
  265. print PASS join(":",@fields),"\n";
  266. print CLEAR "$fields[0]:$pw\n";
  267.  
  268. # 9. word based with special character replacement
  269. do {
  270. @fields = split(/:/,$users[int(rand @users)]);
  271. } while ( exists $pwusers{$fields[0]} );
  272. $pwusers{$fields[0]} = 1;
  273. $salt = join '', ('.', '/', 0..9, 'A'..'Z', 'a'..'z')[int(rand 64),int(rand 64)];
  274. $word = baseword();
  275. $word = substr($word,0,8);
  276. @letters = split(//,$word);
  277. foreach $c (@letters) {
  278. if ( int(rand 2) ) {
  279. $c = uc $c;
  280. } else {
  281. $c = lc $c;
  282. }
  283. $c = $equiv{$c} if defined $equiv{$c};
  284. }
  285. $pw = join("",@letters);
  286. $fields[1] = crypt($pw,$salt);
  287. $#fields -= 1;
  288. print PASS join(":",@fields),"\n";
  289. print CLEAR "$fields[0]:$pw\n";
  290.  
  291. # 10. word based with 2 extra symbols in the middle
  292. do {
  293. @fields = split(/:/,$users[int(rand @users)]);
  294. } while ( exists $pwusers{$fields[0]} );
  295. $pwusers{$fields[0]} = 1;
  296. $salt = join '', ('.', '/', 0..9, 'A'..'Z', 'a'..'z')[int(rand 64),int(rand 64)];
  297. $word = baseword();
  298. $word = substr($word,0,6);
  299. @letters = split(//,$word);
  300. splice(@letters,int(rand(@letters-2)) 1,0,$sym[int(rand @sym)]);
  301. splice(@letters,int(rand(@letters-2)) 1,0,$sym[int(rand @sym)]);
  302. $pw = join("",@letters);
  303. $fields[1] = crypt($pw,$salt);
  304. $#fields -= 1;
  305. print PASS join(":",@fields),"\n";
  306. print CLEAR "$fields[0]:$pw\n";
  307.  
  308. # 11. word based with extra symbol and special character replacement
  309. do {
  310. @fields = split(/:/,$users[int(rand @users)]);
  311. } while ( exists $pwusers{$fields[0]} );
  312. $pwusers{$fields[0]} = 1;
  313. $salt = join '', ('.', '/', 0..9, 'A'..'Z', 'a'..'z')[int(rand 64),int(rand 64)];
  314. $word = baseword();
  315. $word = substr($word,0,7);
  316. @letters = split(//,$word);
  317. foreach $c (@letters) {
  318. $c = $equiv{$c} if defined $equiv{$c};
  319. }
  320. splice(@letters,int(rand(@letters-2)) 1,0,$sym[int(rand @sym)]);
  321. $pw = join("",@letters);
  322. $fields[1] = crypt($pw,$salt);
  323. $#fields -= 1;
  324. print PASS join(":",@fields),"\n";
  325. print CLEAR "$fields[0]:$pw\n";
  326.  
  327. # 12. 5 random alphanumeric characters
  328. do {
  329. @fields = split(/:/,$users[int(rand @users)]);
  330. } while ( exists $pwusers{$fields[0]} );
  331. $pwusers{$fields[0]} = 1;
  332. $salt = join '', ('.', '/', 0..9, 'A'..'Z', 'a'..'z')[int(rand 64),int(rand 64)];
  333. $pw = $ascii[int(rand @ascii)].$ascii[int(rand @ascii)].$ascii[int(rand @ascii)].$ascii[int(rand @ascii)].$ascii[int(rand @ascii)];
  334. $fields[1] = crypt($pw,$salt);
  335. $#fields -= 1;
  336. print PASS join(":",@fields),"\n";
  337. print CLEAR "$fields[0]:$pw\n";
  338.  
  339. # 13. 8 random alphanumeric characters
  340. do {
  341. @fields = split(/:/,$users[int(rand @users)]);
  342. } while ( exists $pwusers{$fields[0]} );
  343. $pwusers{$fields[0]} = 1;
  344. $salt = join '', ('.', '/', 0..9, 'A'..'Z', 'a'..'z')[int(rand 64),int(rand 64)];
  345. $pw = $ascii[int(rand @ascii)].$ascii[int(rand @ascii)].$ascii[int(rand @ascii)].$ascii[int(rand @ascii)].$ascii[int(rand @ascii)].$ascii[int(rand @ascii)].$ascii[int(rand @ascii)].$ascii[int(rand @ascii)];
  346. $fields[1] = crypt($pw,$salt);
  347. $#fields -= 1;
  348. print PASS join(":",@fields),"\n";
  349. print CLEAR "$fields[0]:$pw\n";
  350.  
  351. # 14. 6 random lower case alphabetic characters
  352. do {
  353. @fields = split(/:/,$users[int(rand @users)]);
  354. } while ( exists $pwusers{$fields[0]} );
  355. $pwusers{$fields[0]} = 1;
  356. $salt = join '', ('.', '/', 0..9, 'A'..'Z', 'a'..'z')[int(rand 64),int(rand 64)];
  357. $pw = $lcascii[int(rand @lcascii)].$lcascii[int(rand @lcascii)].$lcascii[int(rand @lcascii)].$lcascii[int(rand @lcascii)].$lcascii[int(rand @lcascii)].$lcascii[int(rand @lcascii)];
  358. $fields[1] = crypt($pw,$salt);
  359. $#fields -= 1;
  360. print PASS join(":",@fields),"\n";
  361. print CLEAR "$fields[0]:$pw\n";
  362.  
  363. # 15. 7 random lower case alphabetic characters
  364. do {
  365. @fields = split(/:/,$users[int(rand @users)]);
  366. } while ( exists $pwusers{$fields[0]} );
  367. $pwusers{$fields[0]} = 1;
  368. $salt = join '', ('.', '/', 0..9, 'A'..'Z', 'a'..'z')[int(rand 64),int(rand 64)];
  369. $pw = $lcascii[int(rand @lcascii)].$lcascii[int(rand @lcascii)].$lcascii[int(rand @lcascii)].$lcascii[int(rand @lcascii)].$lcascii[int(rand @lcascii)].$lcascii[int(rand @lcascii)].$lcascii[int(rand @lcascii)];
  370. $fields[1] = crypt($pw,$salt);
  371. $#fields -= 1;
  372. print PASS join(":",@fields),"\n";
  373. print CLEAR "$fields[0]:$pw\n";
  374.  
  375. # 16. 8 lower case alphabetic characters randomly choosen from the
  376. # following three sets which have the indicated probabilities
  377. # of being choosen:
  378. #
  379. # @ascii1 {asdfghjkl} .7
  380. # @ascii2 {ertyuicvbnm} .29
  381. # @ascii3 {qwzxop} .01
  382.  
  383. do {
  384. @fields = split(/:/,$users[int(rand @users)]);
  385. } while ( exists $pwusers{$fields[0]} );
  386. $pwusers{$fields[0]} = 1;
  387. $salt = join '', ('.', '/', 0..9, 'A'..'Z', 'a'..'z')[int(rand 64),int(rand 64)];
  388. $pw = "";
  389. foreach (1..8) {
  390. $n = int(rand 100);
  391. if ( $n == 0 ) {
  392. $pw .= $ascii3[int(int(rand @ascii3))];
  393. } elsif ( $n < 30 ) {
  394. $pw .= $ascii2[int(int(rand @ascii2))];
  395. } else {
  396. $pw .= $ascii1[int(int(rand @ascii1))];
  397. }
  398. }
  399. $fields[1] = crypt($pw,$salt);
  400. $#fields -= 1;
  401. print PASS join(":",@fields),"\n";
  402. print CLEAR "$fields[0]:$pw\n";
  403.  
  404. # 17. The above (16) is modified by choosing two characters from
  405. # the machine name tyro, keeping them in the same order and
  406. # inserting them in the interior (not at front or end) of 6
  407. # characters choosen as in 16.
  408.  
  409. do {
  410. @fields = split(/:/,$users[int(rand @users)]);
  411. } while ( exists $pwusers{$fields[0]} );
  412. $pwusers{$fields[0]} = 1;
  413. $salt = join '', ('.', '/', 0..9, 'A'..'Z', 'a'..'z')[int(rand 64),int(rand 64)];
  414. $pw = "";
  415. foreach (1..6) {
  416. $n = int(rand 100);
  417. if ( $n == 0 ) {
  418. $pw .= $ascii3[int(int(rand @ascii3))];
  419. } elsif ( $n < 30 ) {
  420. $pw .= $ascii2[int(int(rand @ascii2))];
  421. } else {
  422. $pw .= $ascii1[int(int(rand @ascii1))];
  423. }
  424. }
  425.  
  426. # Select characters from machine name
  427. @letters = split(//,$pw);
  428. $num1 = int(rand($#mname));
  429. $ch1 = $mname[$num1];
  430. $num2 = $num1 1 int(rand($#mname-$num1));
  431. $ch2 = $mname[$num2];
  432.  
  433. # Insert machine name characters into the 6 chosen characters
  434. $pos1 = int(rand($#mname)) 1;
  435. $pos2 = $pos1 1 int(rand($#mname-$pos1));
  436. splice(@letters,$pos1,0,$ch1);
  437. splice(@letters,$pos2,0,$ch2);
  438. $pw = join('',@letters);
  439.  
  440. $fields[1] = crypt($pw,$salt);
  441. $#fields -= 1;
  442. print PASS join(":",@fields),"\n";
  443. print CLEAR "$fields[0]:$pw\n";
  444. close PASS;
  445. close CLEAR;
  446.  
  447. }
  448.  
  449. sub baseword {
  450. while ( (@_ = split(//,($wd = $words[int(rand @words)]))) < 6 )
  451. {
  452. }
  453. return($wd);
  454. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement