 Okay, this is part two in a series on messing with the Canhoon smart plug last video we SSH din saw that were certain commands and also at the very beginning mirror We did a port scan. We found that there is a web server running on there on port 80 but our busy box Doesn't have an HTTP D Damon in it. So we're have to figure out where is this This program coming from so what I'm gonna do is I'm just going to just use fine I'm going to clear the screen here find Slash say we're starting in root. I name meaning Look for a file with this name that I means case insensitive Although it's probably gonna be more case and we'll say anything with HTTP in the name of the file So we'll run that and we get a couple of files here. Definitely seeing some things starting at startup called you HTTP D but really anything in a bin folder and here at the very bottom. We can see under you Usr. We got S been and there's our program So let's go ahead and run that with a dash H for help We do that and we do get a list of of commands here So we can definitely start another instance and have our own web server in but we already have one running on port 80 I really don't need to get a second one running if we can figure out where the files for that are stored if we go to our root directory And we list it out right there is a www folder. So let's go ahead and move into that folder and again It's giving us some sort of index list of the root folder of the web server But there's no files there. So let's go ahead and just create one. Let's just go touch One dot HTML So we have an HTML file here. It's empty. There's nothing in it But let's go ahead and go back to our index list here and click refresh and there it is So it is giving us an index list of the files in here. So again, this thing only has 32 megs of RAM and the the storage on it is even less than that So you're not gonna be doing a lot of storage on here, but we could definitely throw some scripts in here And if this web server runs similar to other HTTP D's Such as busybox we could have executable scripts in here. So let's go ahead and give that a try Also, you know, I could click on this to go in that file, but it's empty. I could also, you know, echo Hello world Close the tag and put that into our one dot HTML And if I was to bring that back and click on that now we get a whole world So you can put your HTML files in there, but again, we're gonna make an executable script. So Again, usually these will be put in a folder called CGI bin. So let's make a directory called CGI dash bin And this is in our WWW folder. So hit enter and we'll move into that folder and We will create a file Basically a shell script file. So I did see when I ran busybox earlier that we do have Vi installed so we do have that as a text editor. So let's go ahead by and I'll call this one on dot CGI Okay now This is a small device. It doesn't have bash on it. It just has a basic shell So we're gonna say bin bin slash sh4 our shebang line not bash And if you remember my tutorials Creating CGI scripts for HTTP Damons we can do content Dash type so we have to echo this if not, it's it's not going to run properly And we're gonna say that it's a text file But what type of text file it's an HTML file and then we need at least one empty line after that after that We can write a shell script however we normally want so if you remember correctly, let me go ahead and Turn on my camera here Okay, so there is the plug With the light and I've exited out of our text editor here And if you remember last time we were able to go echo one to turn the light on into sys class LEDs TP link blue And I'm using tab to autocomplete here relay. I hit control. I'll just bring that up in the screen um And then brightness And that turns the light on and the same thing but putting a zero into there turns it off So let's go ahead and just copy this Copy this to highlight it by into our file And I will just go into edit mode and center click to put that in there And then we have to make it executable so change mod plus x are on cgi and now If we bring back our web browser here And we put in the ip address of the device forward slash There we have it here because I already tested this out cgi bin slash on dot cgi It turns the light on Great So anytime we want to turn the light on we can just Go to that url or call it from a script um Let's go ahead and copy our on to a new file called off dot cgi And then we'll go into off And we'll change it to be off So we just change that zero to or that one to a zero And now if I change in here I can go To our off script And turn it off So I can go back and refresh the on page or I can go forward and refresh that And I can turn them on off with a web browser mean that I can do this from my tablet or phone as well Uh, so that is making a very very basic script So that's great. We have that. Uh, we also want to give some sort of indication to the users So let's real quick just add to these scripts a little bit output Let's say echo And we'll make the font big by using These h1 tags and this is for off And I'm just gonna I like that and go into our on file And change that to be So now when we run those scripts We get a little bit of the visual output on our device Of course, we're going to make something much nicer in the future With buttons and whatnot, but for right now, let's we have an on script and an off script. Let's make a toggle script So what I'm going to do here is I'm going to now Copy either one of those into a script called toggle.cgi And then I'll go into that toggle cgi file And as I said last time we're echoing we're putting into this file because everything in linux anything in unix and unix like systems Is a file whether it's hardware or not. So we're writing to this hardware as if it was a just a plain text file We can also read from it. So what we're going to do is we're going to read from it by using the cat command And we're going to put that into a variable I'm just going to call my variable x just to keep things simple And then I'm going to use these little back ticks. These are not single quotes. These are not apostrophes These are at least on uh standard qwerty keyboard here in the us The little it's the button next to the one on your top row of your keyboard So what that's saying is we're going to put a command in here And whatever the output of that command is we're going to put into the variable called x So we're going to is we're going to cat out So we're going to read this file And if it's on it will equal one and if it's off it will be zero So what we need to do now is we need to check that value after we get it So i'm going to use an if statement and i'm going to say if x dollar sign x saying it's a variable dash eq if it equals zero Well, then We're going to do something And if it's anything else, we're going to do something else And then we're going to close that if statement with an i or fi Which is if backwards okay, so Here we're saying if it's off. Well Let's go ahead and copy this Fix that indentation because it's all indenting which i can't stand and um Here we want to say on and change this to one So what we're doing here is we're checking if x is zero then Well change the value to one and tell the user it's on But if it's is if it isn't zero if it's anything else which it would just be one We're going to turn it off Okay, so i'm going to save that we're going to open up our web browser again, and we're going to go to a toggle dot cji And as you can see it turned it on If i refresh the page it turns it off And if i refresh it again, it turns it on Fresh again, it turns it off and we get the visual output right here on the screen again This will run in pretty much any web browser because the script is on the server itself So it doesn't matter whether you're using wget Actually, let's do that That'd be fun. So let me open up a new shell here. So the top shell here is the shell on the device this bottom shell here Is my local desktop. I can say wget And I can do this And i'll do dash o and i'll just do the output so i don't save any of the output I'll just say output to screen. I'll say dash q for quiet. So I don't see the download process and everything So if I hit enter It tells me right here in my shell that the light's on I don't even have to be in the same room as it if I run it again. I can turn it off Once you create a script like this on a server running on a web server Uh You can access it from any device that has internet access Unlike client side scripts where if We had something going on with java script and i'm not saying anything bad about java script. I love java script It wouldn't work with wget. It wouldn't work with pretty much any text-based web browsers But since everything's being done on the server side through this cgi file Which is just a shell script in this particular case, although you can use any programming language I can write something in c and put it on that device and run it this way But as you can see I can very easily Just keep calling it with wget from my desktop from any computer that has access to that device through the network Because right now we don't have any passwords or anything on it, which you can apply passwords And also eventually it's going to be on an encrypted network and all that jazz But just wanted to show you that you can use a web browser a tablet Phone you probably get a phone that is 15 years old way before smart phones if it had a web browser Which phones back then had very very basic web browsers and you could control this device from it if You had the network connection with it So that's it for this tutorial we're going to play with this device again more next week I thank you for watching. Please visit filmsbychrist.com. That's chris at the k there should be a link in the description And um also there should be a link in the description to all the notes from this project So go ahead and check those out and as always I hope that you have a great day Okay, this is an introduction to filmsbychrist.com I'm chris. That's chris the k That's me right there my daughter ember and my wife jennifer We pretty much live in the swamps of florida I'm a firefighter by day as well as by night. We work long hours But that's not why you're here. You're here about the videos I put up on youtube These videos are mainly about computers And programming which means most of my videos look something like this And if that's what you're interested in great if not, that's all right I do videos on other topics too such as video editing special effects photo editing 3d design and music creation If you are one of my viewers and you enjoy my videos my patreon page is a place where you can go to help support my videos So I ask that you take the time to go to my patreon page and look at different levels of rewards You can receive four different levels of backing There should be a link in the description of this video if you were watching it on youtube Otherwise you can visit patreon.com forward slash metal x 1000 and I thank you for your time And your support Have a great day