APG (Automated Password Generator) でランダムパスワードの自動生成 (゚Д゚ )ウマー

APG (Automated Password Generator) とは?

APG は自動パスワード生成器。システム管理者の「あ~、パスワードなんにしよ~」っていう苦悩を軽減してくれる。パスワードポリシーをランダムにしたり、固定にしたり、文字種、文字長の指定も思いのまま。
expect を入れてあれば、mkpasswd が使えるんだよ。わざわざソースからコンパイルする必要ねーよ。ってゆー人もいると思うけども。悪いとはいわないが、mkpasswd では、パスワード生成ポリシーが固定になってしまう難点がある。文字種、文字長が推測できるので、1 つ同じポリシーで生成されたパスワードを入手できれば、ブルートフォースの必要はなくなってしまう。
オフィシャルサイト: APG (Automated Pasword Generator)


$ cd src/
$ wget http://www.adel.nursat.kz/apg/download/apg-2.2.3.tar.gz
$ wget http://www.adel.nursat.kz/apg/download/apg-2.2.3.tar.gz.md5
$ md5sum --check apg-2.2.3.tar.gz.md5


$ tar zxvf apg-2.2.3.tar.gz
$ cd apg-2.2.3/

インストール先変更のため、Makefile を編集

デフォルトでは、/usr/local にインストールされることになっているが、ここでは、/usr/local/apg-2.2.3 にインストールするよう変更する。

$ cp -a Makefile Makefile.old
$ vi Makefile
--- Makefile.old        2003-08-08 00:40:30.000000000 +0900
+++ Makefile    2006-10-01 15:49:59.000000000 +0900
@@ -39,7 +39,7 @@
 # Directories
 # Install dirs
-INSTALL_PREFIX = /usr/local
+INSTALL_PREFIX = /usr/local/apg-2.2.3
 APG_BIN_DIR = /bin
 APG_MAN_DIR = /man/man1
 APGD_BIN_DIR = /sbi


$ make
$ sudo make install
$ sudo ln -s /usr/local/apg-2.2.3 /usr/local/apg


$ find /usr/local/apg-2.2.3


ぼくがよく使うオプションは以下の 4 つ。

  • -a: パスワード生成をランダムにするかどうかのフラグ。デフォルトは 0。
  • -m: パスワードの最小文字長。デフォルトは 8。
  • -x: パスワードの最大文字長。デフォルトは 10。
  • -n: 生成するパスワードの数。デフォルトは 6。

8 文字から 16 文字の長さでランダムなパスワードを 20 個、生成する例。

$ /usr/local/apg-2.2.3/bin/apg -a1 -m8 -x16 -n20

ヘルプ (-h)

$ /usr/local/apg-2.2.3/bin/apg -h
apg   Automated Password Generator
 Copyright (c) Adel I. Mirzazhanov
apg   [-a algorithm] [-r file]
 [-M mode] [-E char_string] [-n num_of_pass] [-m min_pass_len]
 [-x max_pass_len] [-c cl_seed] [-d] [-s] [-h] [-y] [-q]
-M mode         new style password modes
-E char_string  exclude characters from password generation process
-r file         apply dictionary check against file
-b filter_file  apply bloom filter check against filter_file
 (filter_file should be created with apgbfm(1) utility)
-p substr_len   paranoid modifier for bloom filter check
-a algorithm    choose algorithm
 1 - random password generation according to
 password modes
 0 - pronounceable password generation
-n num_of_pass  generate num_of_pass passwords
-m min_pass_len minimum password length
-x max_pass_len maximum password length
-s              ask user for a random seed for password
-c cl_seed      use cl_seed as a random seed for password
-d              do NOT use any delimiters between generated passwords
-l              spell generated password
-t              print pronunciation for generated pronounceable password
-y              print crypted passwords
-q              quiet mode (do not print warnings)
-h              print this help screen
-v              print version information

マニュアル (man)

$ man /usr/local/apg-2.2.3/man/man1/apg.1
APG(1)                            User Manual                           APG(1)
 apg - generates several random passwords
 apg  [-a  algorithm]  [-M  mode]  [-E char_string] [-n num_of_pass] [-m
 min_pass_len] [-x max_pass_len]  [-r  dictfile]  [-b  filter_file]  [-p
 min_substr_len] [-s] [-c cl_seed] [-d] [-y] [-l] [-t] [-q] [-h] [-v]
 apg generates several random passwords. It uses several password gener-
 ation algorithms (currently two) and a built-in  pseudo  random  number
 Default   algorithm  is  pronounceable  password  generation  algorithm
 designed by Morrie Gasser and described in A Random Word Generator  For
 Pronounceable  Passwords  National Technical Information Service (NTIS)
 AD-A-017676.  The original paper is very old and  had  never  been  put
 online, so I have to use NIST implementation described in FIPS-181.
 Another  algorithm is simple random character generation algorithm, but
 it uses four user-defined symbol sets to produce  random  password.  It
 means  that user can choose type of symbols that should appear in pass-
 word. Symbol sets are: numeric symbol set (0,...,9) ,  capital  letters
 symbol  set  (A,...,Z) , small letters symbol set (a,...,z) and special
 symbols symbol set (#,@,!,...).
 Built-in pseudo random number generator is an implementation  of  algo-
 rithm  described  in Appendix C of ANSI X9.17 or RFC1750 with exception
 that it uses CAST or SHA-1 instead of Triple DES.  It uses  local  time
 with  precision  of  microseconds (see gettimeofday(2)) and /dev/random
 (if available) to produce initial random seed.
 apg also have the ability to check  generated  password  quality  using
 dictionary.  You  can  use  this  ability  if  you specify command-line
 options -r dictfile or -b filtername where dictfile is  the  dictionary
 file name and filtername is the name of Bloom filter file. In that dic-
 tionary you may place words (one per line) that should  not  appear  as
 generated  passwords.  For  example: user names, common words, etc. You
 even can use one of the dictionaries that come with dictionary password
 crackers.   Bloom  filter file should be created with apgbfm(1) utility
 included in apg distribution. In future releases I  plan  to  implement
 some  other  techniques to check passwords (like pattern check) just to
 make life easier.
 Password generation modes options
 -a algorithm
 use algorithm for password generation.
 0 - (default) pronounceable password generation
 1 - random character password generation
 -n num_of_pass
 generate num_of_pass number of passwords. Default is 6.
 -m min_pass_len
 generate  password  with  minimum   length   min_pass_len.    If
 min_pass_len  >  max_pass_len  then max_pass_len = min_pass_len.
 Default minimum password length is 8.
 -x max_pass_len
 generate  password  with  maximum   length   max_pass_len.    If
 min_pass_len  >  max_pass_len  then max_pass_len = min_pass_len.
 Default maximum password length is 10.
 -M mode
 Use symbolsets specified  with  mode  for  password  generation.
 mode is a text string consisting of characters S, s, N, n, C, c,
 L, l. Where:
 S      generator must use special symbol set for every generated
 s      generator should use special symbol set for password gen-
 N      generator must use numeral symbol set for every generated
 n      generator should use numeral symbol set for password gen-
 C      generator must use capital symbol set for every generated
 c      generator should use capital symbol set for password gen-
 L      generator must use small letters  symbol  set  for  every
 generated password (always present if pronounceable pass-
 word generation algorithm is used).
 l      generator should use small letters symbol set  for  pass-
 word generation.
 R,r    not   supported  any  more.  Use  -E  char_string  option
 mode can not be more than 4 characters in length.
 Usage of L, M, N, C will slow down password generation  process.
 -M sncl or -M SNCL or -M Cn
 -E char_string
 exclude  characters in char_string from password generation pro-
 cess (in pronounceable password  generation  mode  you  can  not
 exclude  small  letters). To include special symbols that can be
 recognized by shell (apostrophe, quotes, dollar sign,  etc.)  in
 char_string use the backslashed versions.
 Command  apg -a 1 -M n -n 3 -m 8 -E 23456789 will generate a set
 of passwords that will look like this
 Command apg -a 1 -M nc -n 3 -m 26 -E  GHIJKLMNOPQRSTUVWXYZ  will
 generate a set of passwords that will look like this
 Password quality control options
 -r dictfile
 check generated passwords for their appearance in dictfile
 -b filter_file
 check  generated  passwords for their appearance in filter_file.
 filter_file should be created with apgbfm(1) utility.
 -p min_substr_len
 this option tells apg(1) to check every substring of the  gener-
 ated password for appearance in filter_file. If any of such sub-
 strings would be found in the filter_file then  generated  pass-
 word  would  be  rejected  and apg(1) will generate another one.
 min_substr_len specifies  minimum  substring  length  to  check.
 This option is active only if -b option is defined.
 Pseudo random number generator options
 -s     ask user for random sequence for password generation
 -c cl_seed
 use  cl_seed  as a random seed for password generation. I use it
 when i have to generate passwords in a shell script.
 Password output options
 -d     do NOT use any delimiters between generated passwords. I use  it
 when i have to generate passwords in a shell script.
 -y     print   generated  passwords  and  crypted  passwords  (see  man
 -q     quiet mode (do not print warnings)
 -l     spell genetated passwords. Useful when you want to  read  gener-
 ated password by telephone.
 WARNING: Think twice before read your password by phone.
 -t     print pronunciation for generated pronounceable password
 -h     print help information and exit
 -v     print version information and exit
 apg -a 0 -M sncl -n 6 -x 10 -m 8 (new style)
 If  you want to generate really secure passwords, you should use option
 -s. To simplify apg usage, you can write  a  small  shell  script.  For
 [begin]----> pwgen.sh
 /usr/local/bin/apg -m 8 -x 12 -s
 [ end ]----> pwgen.sh
 On  successful completion of its task, apg will complete with exit code
 0.  An exit code of -1 indicates an error occurred.  Textual errors are
 written to the standard error stream.
 If /dev/random is not available, apg will display a message about it.
 None.   If you’ve found one, please send bug description to the author.
 apgd(8), apgbfm(1)
 Adel I. Mirzazhanov, <a-del@iname.com>
 Project home page: http://www.adel.nursat.kz/apg/
Automated Password Generator      2003 Aug 04                           APG(1)