 Okay, we've been looking at networks and servers, and so far we've looked at Busybox, HTTPD, we looked at creating our own access point with a computer and a Wi-Fi card. We've also looked at using Python to not only set up a web server, but set up a web server that you have server-side scripts on. Now we're looking at a very, very, very simple way to create a very, very simple web server. This is something you'd probably use in a pinch. You wouldn't use actually as a web server, and it's probably something that you may have seen before. It's very commonly used, but I'm gonna take it a step further than most examples do. It's gonna be using Netcat, which you can install in your system. There's also a very basic version of it, built into most versions of Busybox. It's a little more simple than, it's not a full-featured one, but it's there, and it allows you to basically pipe a file or the output of some sort of program into, as output for a web device. But lots of times, well, it's basically that one file it pipes over into your web display, your web browser. And to access other files, like let's say you wanna have a web page with images in it, is a little more, well, that's what we're gonna look at after we look at the basics here. So, here we go, let me make my font a little bit bigger here, and we'll bring this down here. So here we have a web browser. I set up, I already pointed it to my computer here. Again, this is on my local network. I know my IP address, and I'm gonna start the server on port 800 because I know a regular user can use that port, report 80, usually you need more permissions too, so whatever permissions your user has. And what I'm gonna type here is I'm gonna say, NC, or you can type out netcat, either should work, dash i, and of course you need netcat installed, so install that through your repositories. And I'm gonna say, so dash l means listen, dash p means port, I'm gonna say 8,000. And then I'm also gonna say dash q1, that one's kind of optional, basically that's saying is after a second, quit, kill the connection, because it shouldn't take more to pipe out this simple display, and you don't want the connection to stay open for some reason, so this will be like, hey, after a second, quit, if things aren't going right. Okay, so we did that, and that will listen on a port, but not much is gonna happen at this point because we need to give it some sort of information. So let's go ahead and I'm gonna split the screen here, and I'm gonna create a new web page, I'm gonna say vim embed.html, well no, I'll just call this nc.html, and in here I'll just say, h1 hello from netcat, I will save that file, and what I'm gonna do is I'm gonna say, okay, take my nc.html file, and that's gonna be the output. So with this web server, you're not gonna be able to direct it to certain files. Someone connects on this port, they're gonna get the output of this file no matter what else they type in. So here we go, I'm gonna hit enter to start that up, up here, I've already got the IP address and the port number put in, and I'm gonna hit enter, and you can see hello from netcat. Now if I come up here and I hit refresh, we get web page not available again, and if someone else tries to connect, they're gonna get the same thing, because as you can see down here, our server is no longer running. This is what I'm trying to do. Okay, so we need to put our netcat into loop and there's different versions of netcat out there. I've seen some commands that are supposed to do this built into netcat and they don't always work, so I'm gonna show you another way to do it. We're gonna say while, true, so we're just gonna create a while loop on our shell here, do, and then we'll say netcat-l for listen-p for port, 8000 in this case, dash q1, and we'll pipe in our NC file or netcat file or HTML file, and we'll say done. What's gonna do is we're gonna run that, and up here I'll hit F5, and as you can see it says hello from netcat, we get some output that our browser actually sent to netcat, and you can see that it's still running, so I can hit F5 again, and F5 again, and someone else can connect. Basically it's going to, netcat's sitting there waiting, it's listening when someone connects, it gives that information, netcat stops running, but our while loop starts it up again. So that's one way to do it. Again, this is not something you wanna do for a commercial website. This is something you do in a pinch. Okay, so that's working great. I'm gonna go ahead and Control-C does not seem to wanna stop that, so what I'm going to do is I am just going to close that shell. So that's normally how I kill that. You could also, I guess, use the kill command to kill the process. Okay, so we've done that. If I, again, up here refresh our servers down. What happens if we want to display an image out to the web server? Well, we can do that as well. So let's go ahead and just again, netcat-listen-port-8000-q1, and we'll redirect, I have in this folder, fbk.png, it's films by Chris, just basic png. I'll hit enter, the server's against listening. I didn't put it in the while loop, just so I don't have to kill the shell each time here, but I'm gonna come up here, and again, I don't have to put in any file name because no matter what file name I put in there, it's just gonna output the same output on that port no matter what. Well, my browser just automatically refreshed because it realized the server was back up, but you can see it displayed, wwfilmsbychris.com, it's a png file. It's basically just outputted that file. So that's one way you can share images, but how can you put an image into a web page? So normally, if we go back into our netcat HTML here, I could do something like this. I can say, well, we'll put it on, well, I don't need to let him break those or header file. Okay, anyway, I can say imgsource equals, and filmsbychris.png is the name of the file inside the folder we're at, and that on a regular web page would work. Let's go ahead and save that, close that, run our server again here, and up here hit F5. And that's because I typed in the wrong command down here. I piped out the image again. We wanna pipe out nc.html. Now we run it, we refresh up here, and you can see it says hello from netcat, but our image is broke, because netcat doesn't know how to serve up files other than the one we're redirecting into it with the less than symbol. So how can we get a web page with images and other data in there when we're only able to pipe in this one file? Well, you may or may not know this, but you can embed images into an HTML file. So instead of having HTML file and your images separate, you can have them all built into the HTML file themselves in a plain text using base64. I'm not gonna get into too much about base64 today. Base64 is a great, great thing. It takes any binary file you have and will convert to plain text as key so you can transmit stuff. If you ever looked at the raw data from an email, if there's an attachment, the attachment is sent to your email program in base64. So what we have to do is we have to generate base64 data for our image. So first things first, let's go into our netcat.html file. And here, instead of saying the name of the file, because again, netcat doesn't know what to do with that, it's going, oh, you're looking for this, I don't know how to serve that up, because by the time we even look at that, once it sends the one file, netcat closes. So we're gonna say data colon image forward slash PNG. This is saying, okay, the source of this image is gonna be a data, it's gonna be an image, it's gonna be a PNG image in this case. Semi colon and we're gonna say base64, we're telling it, okay, use base64, comma. Now we need to put the base64 information, which is gonna be really, really long. Probably on your system array, you have base64 installed, if you type base64 and the name of a file, in this case, filmsbychris.pngfbk.png, you can see it outputs all this plain text. That is the image changed from a binary file into a plain ASCII text, which characters are readable to us, but obviously it's, we can't view that image, look at that and go, oh, that's an image of this. So we're gonna copy and paste that, it's kind of long for me to highlight it all. So I have X clip installed. If you don't, it's in your repositories, basically that's gonna pipe that into my clipboard. So boom, right now I can go in now, I can go and paste that into my, you can also redirect it into a file if you want, and then use that. Anyway, I'm gonna go into my HTML file here, hit I, I'm gonna center click here, and give it a second. Vim is going, oh, okay, that's a lot of data, let's put all that here, it's gonna take a couple of seconds because it's an image. There we go, it's all in there, I can now save that. Hit up arrow a few times, so now we're going to run our command again. Netcat, listen, port 8000, quit after one second, redirect this image, or this HTML file, which has the image built into it. Run that, refresh up here, and there we go, we have our HTML content and the image, and of course you can do this throughout the page. Now, remember, now that HTML file that used to be the small little text file is now rather large, if we actually list out all the files in this directory, you can see that our filmsbychris.png is 57 kilobytes, not that big, our HTML file is 76 kilobytes. And, part of that is because there is more data in there, but also base64 tends to be a little bit larger than the original little binary file, but keep that in mind, if you're putting large images in there, your HTML file is going to get rather large, it's going to take longer to pipe it, but that is it, and in fact, if I was to open up in my web browser here, I'm using Chrome, I'll hit F12 to bring up my little console here, and I look at network. On a regular web page, let's go ahead and start our server up, and up here I'll hit F5 to refresh. You can see it, it shows right here, it doesn't say a file name, it's saying, okay, it's transferring this data as an image. And so, keep that in mind, it's not getting it from a separate file, it's actually embedded in an HTML file, and in most cases, web servers, websites, you don't want to do that, but if you ever needed, that's actual bonus tip outside of this Netcat tutorial, you could send an HTML file to somebody, as a single file with images if you ever wanted to. I've never done that, but you can. So, that is it. Little quick look at base 64 there, which is a great thing, used a lot especially with HTML5 for storing images created on canvas and stuff like that, not getting into that today, but I hope that you learned something, because again, this using Netcat as a web server is a fairly common hack that people use to get a web server to share a file real quick. As you saw, you can share a file by piping the file or the HTML, but at the same time, I thought I'd take it a step further in case you've already seen that and show you how you can embed those images in there, so you can have a full web page if you wanted with images and other data built in using base 64. So, as always, I hope that you enjoyed the tutorial, please visit my website, philonsbychrist.com, that's Chris at the K, there should be a link in the description. If you like this video, let me know by one, giving this video a thumbs up. Two, commenting below and let me know that you like it so that I know what topics people like and I know to do more. And also, it helps me out a lot if you share these videos wherever, Facebook, Google+, Twitter, share it, get me more viewers, I really appreciate that. Also, if you wanna support me, you can support me at patreon.com for it slash mail x1000, I appreciate that, but if you can't afford to do that or for some reason you don't want to do that, you can help me by sharing this video. And as always, I hope that you have a great day. If you enjoy my tutorials and would like to see more, please think about contributing to my Patreon account at patreon.com forward slash mail x1000.