Skip to main content
update script and output to place bias at top
Source Link
Aaron Toponce
  • 4.9k
  • 2
  • 21
  • 12
#!/bin/bash

# This repeatedly changes a `saltuser' password
# and grabs the salt out of /etc/shadow.
# Requires root and the existence of `saltuser' user.

if [ $EUID -ne 0 ]; then
    echo "This script requires root access to read /etc/shadow."
    exit 1
fi

grep -q saltuser /etc/passwd

if [ $? -ne 0 ]; then
    echo "This script requires the 'saltuser' to be present."
    exit 2
fi

: > /tmp/salts.txt

for i in {1..1000}; do
    PW=$(tr -cd '[[:print:]]' < /dev/urandom | head -c 64)
    echo "saltuser:${PW}" | chpasswd -c SHA256 -s 0 2> /dev/urandom
    awk -F '$' '/^saltuser/ {print $3}' /etc/shadow >> /tmp/salts.txt
done

while read LINE; do
    # 6th character in the salt
    echo ${LINE:5:1}
done < /tmp/salts.txt | sort | uniq -c | sort -nrn
512 /
 314 1T
  313 8W
 13 4v
 .13 t
 12 4x
 012 m
 12 4d
 211 p
 11 4L
 e11 F
 11 4 
 h10 s
 10 4l
 n10 g
 10 5f
 310 7
 10 56
 a 9 Z
  59 Cw
  59 iN
  59 IH
  59 JG
  59 oE
  59 QA
  58 VY
  68 5X
  68 Kr
  68 SO
  68 Uj
  68 yc
  68 zB
  78 Db
  78 k9
  7 Mu
  7 PR
  7 q
  7 RP
  7 uM
  87 9k
  87 bD
  86 Bz
  86 cy
  86 jU
  86 OS
  86 rK
  86 X5
  85 YV
  95 AQ
  95 Eo
  95 GJ
  95 HI
  95 Ni
  95 wC
  95 Za
 10 6
 105 73
 10 f
 104 gn
 10 l
 104 sh
 11 4
  11 Fe
 11 L
 114 p2
 12 d
 124 m0
 12 x
 134 t.
 13 v
 133 W8
 14 T
5123 /1
504 /
 313 7P
 13 4B
 K12 s
 12 4Z
 N11 e
 11 4Y
 l11 O
 11 4L
 n11 G
 10 5w
 210 u
 10 5q
 310 i
 10 5h
 V10 X
 10 5I
 j10 E
  59 mx
  59 rg
  69 .f
  69 5W
  69 JF
  69 QC
  69 a9
  69 d8
  68 pv
  78 1t
  78 4c
  78 6b
  78 AS
  78 MH
  78 RD
  78 T0
  7 Uz
  7 ky
  7 o
  7 yk
  7 zU
  87 0T
  87 DR
  87 HM
  87 SA
  87 b6
  87 c4
  87 t1
  86 vp
  96 8d
  96 9a
  96 CQ
  96 FJ
  96 W5
  96 f.
  95 gr
  95 xm
 10 E
 105 Ij
 10 X
 105 hV
 10 i
 105 q3
 10 u
 105 w2
 11 G
 114 Ln
 11 O
 114 Yl
 11 e
 124 ZN
 12 s
 134 BK
 13 P
5043 /7
#!/bin/bash

# This repeatedly changes a `saltuser' password
# and grabs the salt out of /etc/shadow.
# Requires root and the existence of `saltuser' user.

if [ $EUID -ne 0 ]; then
    echo "This script requires root access to read /etc/shadow."
    exit 1
fi

grep -q saltuser /etc/passwd

if [ $? -ne 0 ]; then
    echo "This script requires the 'saltuser' to be present."
    exit 2
fi

: > /tmp/salts.txt

for i in {1..1000}; do
    PW=$(tr -cd '[[:print:]]' < /dev/urandom | head -c 64)
    echo "saltuser:${PW}" | chpasswd -c SHA256 -s 0 2> /dev/urandom
    awk -F '$' '/^saltuser/ {print $3}' /etc/shadow >> /tmp/salts.txt
done

while read LINE; do
    # 6th character in the salt
    echo ${LINE:5:1}
done < /tmp/salts.txt | sort | uniq -c | sort -n
  3 1
  3 8
  4 .
  4 0
  4 2
  4 e
  4 h
  4 n
  5 3
  5 a
  5 C
  5 i
  5 I
  5 J
  5 o
  5 Q
  5 V
  6 5
  6 K
  6 S
  6 U
  6 y
  6 z
  7 D
  7 k
  7 M
  7 P
  7 q
  7 R
  7 u
  8 9
  8 b
  8 B
  8 c
  8 j
  8 O
  8 r
  8 X
  8 Y
  9 A
  9 E
  9 G
  9 H
  9 N
  9 w
  9 Z
 10 6
 10 7
 10 f
 10 g
 10 l
 10 s
 11 4
  11 F
 11 L
 11 p
 12 d
 12 m
 12 x
 13 t
 13 v
 13 W
 14 T
512 /
  3 7
  4 K
  4 N
  4 l
  4 n
  5 2
  5 3
  5 V
  5 j
  5 m
  5 r
  6 .
  6 5
  6 J
  6 Q
  6 a
  6 d
  6 p
  7 1
  7 4
  7 6
  7 A
  7 M
  7 R
  7 T
  7 U
  7 k
  7 o
  7 y
  7 z
  8 0
  8 D
  8 H
  8 S
  8 b
  8 c
  8 t
  8 v
  9 8
  9 9
  9 C
  9 F
  9 W
  9 f
  9 g
  9 x
 10 E
 10 I
 10 X
 10 h
 10 i
 10 q
 10 u
 10 w
 11 G
 11 L
 11 O
 11 Y
 11 e
 12 Z
 12 s
 13 B
 13 P
504 /
#!/bin/bash

# This repeatedly changes a `saltuser' password
# and grabs the salt out of /etc/shadow.
# Requires root and the existence of `saltuser' user.

if [ $EUID -ne 0 ]; then
    echo "This script requires root access to read /etc/shadow."
    exit 1
fi

grep -q saltuser /etc/passwd

if [ $? -ne 0 ]; then
    echo "This script requires the 'saltuser' to be present."
    exit 2
fi

: > /tmp/salts.txt

for i in {1..1000}; do
    PW=$(tr -cd '[[:print:]]' < /dev/urandom | head -c 64)
    echo "saltuser:${PW}" | chpasswd -c SHA256 -s 0 2> /dev/urandom
    awk -F '$' '/^saltuser/ {print $3}' /etc/shadow >> /tmp/salts.txt
done

while read LINE; do
    # 6th character in the salt
    echo ${LINE:5:1}
done < /tmp/salts.txt | sort | uniq -c | sort -rn
512 /
 14 T
 13 W
 13 v
 13 t
 12 x
 12 m
 12 d
 11 p
 11 L
 11 F
 11 4 
 10 s
 10 l
 10 g
 10 f
 10 7
 10 6
  9 Z
  9 w
  9 N
  9 H
  9 G
  9 E
  9 A
  8 Y
  8 X
  8 r
  8 O
  8 j
  8 c
  8 B
  8 b
  8 9
  7 u
  7 R
  7 q
  7 P
  7 M
  7 k
  7 D
  6 z
  6 y
  6 U
  6 S
  6 K
  6 5
  5 V
  5 Q
  5 o
  5 J
  5 I
  5 i
  5 C
  5 a
  5 3
  4 n
  4 h
  4 e
  4 2
  4 0
  4 .
  3 8
  3 1
504 /
 13 P
 13 B
 12 s
 12 Z
 11 e
 11 Y
 11 O
 11 L
 11 G
 10 w
 10 u
 10 q
 10 i
 10 h
 10 X
 10 I
 10 E
  9 x
  9 g
  9 f
  9 W
  9 F
  9 C
  9 9
  9 8
  8 v
  8 t
  8 c
  8 b
  8 S
  8 H
  8 D
  8 0
  7 z
  7 y
  7 o
  7 k
  7 U
  7 T
  7 R
  7 M
  7 A
  7 6
  7 4
  7 1
  6 p
  6 d
  6 a
  6 Q
  6 J
  6 5
  6 .
  5 r
  5 m
  5 j
  5 V
  5 3
  5 2
  4 n
  4 l
  4 N
  4 K
  3 7
Source Link
Aaron Toponce
  • 4.9k
  • 2
  • 21
  • 12

mkpasswd(1) might be a front-end to crypt(3), but it's not the same as running chpasswd(1), which is part of the "shadow-utils" package on CentOS and "passwd" on Debian. Instead, you should compare apples-to-apples. Consider the following script:

#!/bin/bash

# This repeatedly changes a `saltuser' password
# and grabs the salt out of /etc/shadow.
# Requires root and the existence of `saltuser' user.

if [ $EUID -ne 0 ]; then
    echo "This script requires root access to read /etc/shadow."
    exit 1
fi

grep -q saltuser /etc/passwd

if [ $? -ne 0 ]; then
    echo "This script requires the 'saltuser' to be present."
    exit 2
fi

: > /tmp/salts.txt

for i in {1..1000}; do
    PW=$(tr -cd '[[:print:]]' < /dev/urandom | head -c 64)
    echo "saltuser:${PW}" | chpasswd -c SHA256 -s 0 2> /dev/urandom
    awk -F '$' '/^saltuser/ {print $3}' /etc/shadow >> /tmp/salts.txt
done

while read LINE; do
    # 6th character in the salt
    echo ${LINE:5:1}
done < /tmp/salts.txt | sort | uniq -c | sort -n

Output from Debian Sid:

  3 1
  3 8
  4 .
  4 0
  4 2
  4 e
  4 h
  4 n
  5 3
  5 a
  5 C
  5 i
  5 I
  5 J
  5 o
  5 Q
  5 V
  6 5
  6 K
  6 S
  6 U
  6 y
  6 z
  7 D
  7 k
  7 M
  7 P
  7 q
  7 R
  7 u
  8 9
  8 b
  8 B
  8 c
  8 j
  8 O
  8 r
  8 X
  8 Y
  9 A
  9 E
  9 G
  9 H
  9 N
  9 w
  9 Z
 10 6
 10 7
 10 f
 10 g
 10 l
 10 s
 11 4
 11 F
 11 L
 11 p
 12 d
 12 m
 12 x
 13 t
 13 v
 13 W
 14 T
512 /

Output from CentOS 7:

  3 7
  4 K
  4 N
  4 l
  4 n
  5 2
  5 3
  5 V
  5 j
  5 m
  5 r
  6 .
  6 5
  6 J
  6 Q
  6 a
  6 d
  6 p
  7 1
  7 4
  7 6
  7 A
  7 M
  7 R
  7 T
  7 U
  7 k
  7 o
  7 y
  7 z
  8 0
  8 D
  8 H
  8 S
  8 b
  8 c
  8 t
  8 v
  9 8
  9 9
  9 C
  9 F
  9 W
  9 f
  9 g
  9 x
 10 E
 10 I
 10 X
 10 h
 10 i
 10 q
 10 u
 10 w
 11 G
 11 L
 11 O
 11 Y
 11 e
 12 Z
 12 s
 13 B
 13 P
504 /

So, the problem isn't unique to CentOS, but likely coming from upstream where both projects are pulling from.