The idea is as follows. Allow users to use their system logins and passwords to access a certain web service running on the same machine. At the same time, for greater security over the network, transfer only hashes from entered passwords connected with random data from the server. The passwords will be checked by a separate daemon associated with the web service on a unix-socket.

OS Ubuntu.

Are there any ready-made solutions? Is it possible to program this using the PAM library? Will this limit the PAM configuration?

As far as I understand, all existing plug-ins and authentication patches for http-servers via PAM receive passwords from the user only in open form, apparently this follows from the capabilities of PAM.

Description of one of the similar solutions: https://davidben.net/thesis.pdf

  • To transfer the hash over the network, you need to get the hash on the client side exactly according to the algorithm that is used on your server. in HTTPS it is easier to pass an open password. In general, as for me, the idea is strange. Usually, it is generally accepted to unbind services from system passwords as much as possible so that a password leak compromises only this user in this service, and not the system as a whole - Mike
  • @Mike, well, for example, samba synchronizes its passwords with system passwords by default - sercxjo
  • one
    Are there any ready-made solutions? - ldap - aleksandr barakin
  • @alexanderbarakin, it is not clear how ldap relates to the question. - sercxjo
  • one
    @sercxjo, allows users to use their unique usernames and passwords to access a certain service (including the login in the operating system). - aleksandr barakin pm

1 answer 1

PAM receives passwords in clear text. Although it is theoretically possible to write a PAM module, forcing the user to solve an example with data and a function known only to the user and enter the answer instead of the password. Passwords are usually stored in the form of hashes (it depends on the modules used) with the salt (an additional string that makes the hashes of the same passwords unique), which is calculated at the time of setting the new password depending on the time and other random data. A hash is the result of irreversible password encryption, for example, when the key is the password itself. PAM itself does not provide for the application to work with these hashes, they remain inside the modules.

Thus, you need to either intercept passwords through your own PAM module at the time of their installation, or use getspnam() to get the hash from /etc/shadow .

In the first case, the password hashes calculated in the module (so that the password itself could not be known) can be written to a file accessible only to the checking daemon for the web server. The web client will have to hash the password twice. The disadvantages of this method are that after installing the package so that the user can log in to the web service, he must first change the password. And if remote password storage is used, and the user changes his password from another computer, the old password will be valid in the web service.

The second case requires transferring the hash and the salt from /etc/shadow to the web client so that it can hash the password in the same way and then hash it again with random data from the server. If PAM is configured with modules other than pam_unix , the user whose password is stored in a different location must have a password in /etc/shadow as well in order to be able to use the web service. The hashing method must be configured so that the web client can reproduce it.

In the testing daemon itself, there is no need to use PAM.

This non-SSL authentication method is vulnerable to intercepting a password if an attacker can not only monitor traffic, but also interfere with it. By adding his code to the script, he can force the browser to send the password in clear text before hashing.