Level 0
-
Level Goal:
- Your goal is to connect to port 5842 on vortex.labs.overthewire.org and read in 4 unsigned integers in host byte order. Add these integers together and send back the results to get a username and password for vortex1. This information can be used to log in using SSH.
Solution:
#include<iostream>
#include<boost/asio.hpp>
#include<boost/array.hpp>
using namespace std;
using boost::asio::ip::tcp;
int main(int argc,char**argv){
if(argc!=3){
cerr<<"Usage: prog <host> <port>"<<endl;
return -1;
}
try{
boost::asio::io_service io_service;
tcp::resolver resolver(io_service);
tcp::resolver::query query(tcp::v4(),argv[1],argv[2]);
tcp::resolver::iterator iter=resolver.resolve(query);
tcp::resolver::iterator end;
tcp::socket socket(io_service);
boost::system::error_code error=boost::asio::error::host_not_found;
while(error&&iter!=end){
socket.close();
socket.connect(*iter++,error);
}
if(error){
throw boost::system::system_error(error);
}
unsigned int sum=0;
for(int i=0;i<4;++i){
unsigned int tmp;
socket.receive(boost::asio::buffer(&tmp,sizeof(tmp)));
sum+=tmp;
}
socket.send(boost::asio::buffer(&sum,sizeof(sum)));
boost::array<unsigned char,512> buf;
socket.receive(boost::asio::buffer(buf));
cout<<buf.data()<<endl;
}catch(std::exception& e){
cerr<<"Exception: "<<e.what()<<endl;
}
return 0;
}