Wargames-Vortex Level 0

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.
Note:  vortex is on an 32bit x86 machine (meaning, a little endian architecture)
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;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值