 Hey everyone, welcome back to another Python tutorial. We're still looking at UNIX specific services And this time we're looking at a new module one that we were kind of branching off of from the last video on PWD or the password database. This one is SPWD, which is the shadow password database. We were looking at the attributes and the kind of object instruction we were receiving from the last module PWD and the portion that should have given us the user's password actually gave us an X or sometimes in other cases an asterisk and this X, I believe, which we saw on note actually in the old documentation here. I'll show you PWD. It tells us that if it's not available, you can try the SPWD module, which should contain access to the encrypted passwords in the ItSetRushShadow file. So let's take a look at that. Again, this module provides access to the UNIX shadow password database. It's available on all UNIX versions and it looks like it has the same functionality as the PWD module. It still returns things from the password database as tuple-like objects, which has attributes and indexes that refer to the username, the password, of course, which hopefully will be encrypted and actually visible this time around, the date of the last change, days between changes, and more stuff regarding the password. So hopefully we'll get a little bit closer to understanding these passwords, being able to manipulate them the way we want to. Remember in the last tutorial, we actually created a new user. It was Fubar. So if I try and log in again as Fubar with su-fubar, the password we set was Apples and when I log in, I can say who am I and now it's obvious that I'm Fubar. So we should be able to play with this user with the Apples password to kind of experiment and see more of what we're working with here. So these attributes and things in the password object that we get returned to us are normally strings, at least for the name and password items. Everything else is an integer because that's just what it needs to be and of course key errors are raised if we don't find them. So it has pretty similar functions to the last PW module, PWD module. Kind of the same functionality with a given username and P all return the list of everything. So let's try and play with them. I'll fire up my shell here. Let's import spwd. spwd gets sp all. Now if I run this, I'm not getting anything. Why is that? When we use PWD the other one, we got like freaking everything, right? We got PW all and we get all of these users and all the information about them. Why is that? What are we overlooking here? Now if we head back to our documentation, I skipped over a kind of a crucial line intentionally so you guys might have the same logic process that I did when I first played with this module. I didn't realize you have to be root to be able to do this. You must have enough privileges to access the shadow password database, which usually means you have to be root. So the user that I'm running right now or John, like we saw in the last video, I don't have the privileges to actually be able to read the shadow password database. So when I try and run get sp all, I'm gonna get return an empty list. I'm gonna be returned nothing valuable. So let's play with this a little bit more. I told you that everything was actually stored in the etc shadow database for shadow encrypted passwords or shadow password systems. So let's take a look at that. Let's try and cat it out just like just like how we did with the etc past WD database. We can see that one pretty easily, but if we try and cat etc shadow. Oh, permission denied, right? It's because we need to be root. We need to have the privileges to be able to do this. So if I try and actually pseudo cat etc shadow. Normally you'd have to type in your password if you're in a new terminal since I already created an old user with this terminal. I don't have to. But let's check this out. I'm gonna go I'm gonna put this in the less so we can look through it. And hey, we see all the same users that we were looking at before with a similar kind of setup with etc the password file Where things are separated by colons and we have different fields and different indexes and attributes that we're actually seeing. So hey, there's the john user. That's me. And there's the foobar user that we created. So this Gunk, I think should be the encrypted password, right? The second index. Is it does it say in our documentation? Yeah, PW password is the Actually for SPWD in this database SPPWD is the encrypted password. So hey, that gets us a little bit closer to looking at passwords. So let's try and play with this now in Python because right now we were just looking at the file and the Linux shell But we need to be able to do this with our actual Python program. So I'm gonna close this shell that I have open and I'm actually gonna run pseudo idle So now I have a root shell So I can use So let's go ahead and import SPWD and Now when we run get SP all Hey, we get all the stuff that we wanted to see and of course now we can use SPWD get SPNAM To use it with a name and let's look at foobar and now we get our foobar user and this encrypted password that we want to be able to look at cool Let's uh Let's let's see. That's to be the first one index, right? Yeah, okay. There's the password and That's exactly what we want to be looking at We have all this other information that's actually stored in the documentation here SP flag SP aspire and all these other things that you might be interested in but for us We want to be a little bit mischievous. We want to look at these passwords on a Linux system So thank you guys for watching this tutorial. I know this one is a little bit Simpler than the last one since you already introduced of this this kind of module and these kind of things of what it does Pretty simple just returns this object and you can look at the user database and the password database And now we're getting closer and closer to looking at actual passwords They are encrypted, but you know what we can work with that because remember Back here in the PWD database documentation. It told us Normally these passwords are encrypted with a DES derived algorithm With the module crypt and Python At least we can go through with that algorithm to Encrypt things with that. So hopefully you guys might see a little bit of potential here And we'll move on to it in the next tutorial. Thanks everyone. See you soon