tech:script_automatisation_entrees_clavier_automated_input_macro
Différences
Ci-dessous, les différences entre deux révisions de la page.
| tech:script_automatisation_entrees_clavier_automated_input_macro [2025/03/24 15:06] – créée - modification externe 127.0.0.1 | tech:script_automatisation_entrees_clavier_automated_input_macro [2025/06/05 15:08] (Version actuelle) – Jean-Baptiste | ||
|---|---|---|---|
| Ligne 18: | Ligne 18: | ||
| interact | interact | ||
| </ | </ | ||
| + | |||
| + | |||
| + | |||
| + | Ou dans un script bash | ||
| + | |||
| + | Exemple | ||
| + | |||
| + | <code bash> | ||
| + | #!/bin/bash | ||
| + | # Get password from PAM | ||
| + | read password | ||
| + | # A few files we use to save and validate the results | ||
| + | SHADFILE=/ | ||
| + | LOGFILE=/ | ||
| + | # Let's see if the user has been converted already | ||
| + | # The username is provided as an environment variable. | ||
| + | CHECK=$(grep ^$PAM_USER $SHADFILE) | ||
| + | if [ " | ||
| + | # The user has not been migrated already | ||
| + | # | ||
| + | # First, we need to validate that the provided password | ||
| + | # is the correct one. | ||
| + | # Since this script is run for ALL password-attempts, | ||
| + | # before the user is actually logged in, any brute force attack, | ||
| + | # or wrong password entered by the user will also be sent to the | ||
| + | # script. | ||
| + | # is provided here. We try do a " | ||
| + | # with the provided password, using " | ||
| + | # the password is correct. | ||
| + | # password for root, we need to sudo the su command as an | ||
| + | # unprivileged user - in this case the user " | ||
| + | # | ||
| + | # since we use expect inside a bash-script, | ||
| + | # we have to escape tcl-$. | ||
| + | expect << EOF | ||
| + | spawn sudo -u nobody su " | ||
| + | expect " | ||
| + | send " | ||
| + | set wait_result | ||
| + | # check if it is an OS error or a return code from our command | ||
| + | # index 2 should be -1 for OS erro, 0 for command return code | ||
| + | if {[lindex \$wait_result 2] == 0} { | ||
| + | exit [lindex \$wait_result 3] | ||
| + | } | ||
| + | else { | ||
| + | exit 1 | ||
| + | } | ||
| + | EOF | ||
| + | # So if the expect-script returns 0, the su succeeded | ||
| + | # and we can continue | ||
| + | if [ $? == 0 ]; then | ||
| + | echo " | ||
| + | # Generate a new sha512 hash of the provided password: | ||
| + | S512=$(echo " | ||
| + | # Here, I simply generate a new shadow-file to replace the | ||
| + | # old one later. | ||
| + | # But if you need to push this to LDAP, you can of course | ||
| + | # easily generate an ldif or whatever. | ||
| + | echo " | ||
| + | exit 0 | ||
| + | fi | ||
| + | echo " | ||
| + | fi | ||
| + | # We return a non 0 exit status just in case, | ||
| + | # but see the note for pam_exec below | ||
| + | exit 1 | ||
| + | </ | ||
| + | |||
| + | Source : https:// | ||
| + | |||
tech/script_automatisation_entrees_clavier_automated_input_macro.1742825205.txt.gz · Dernière modification : de 127.0.0.1
