pwn++  0.1.4
A (toy) Windows & Linux pwn library to play with modern C++.
Tube.hpp
1 #pragma once
2 
3 #include "Common.hpp"
4 
5 namespace pwn::Net
6 {
10 class Tube
11 {
12 public:
16  static constexpr usize PIPE_DEFAULT_SIZE = 1024;
17 
21  static constexpr u8 LINE_SEPARATOR = '\n';
22 
26  static constexpr std::string_view INTERACTIVE_PROMPT = "(pwn)> ";
27 
28 
34  PWNAPI Result<usize>
35  send(std::vector<u8> const& str);
36 
43  PWNAPI Result<usize>
44  send(std::string const& str);
45 
46 
53  Result<std::vector<u8>>
54  recv(_In_ usize size = Tube::PIPE_DEFAULT_SIZE);
55 
56 
63  Result<usize>
64  sendline(_In_ std::vector<u8> const& data);
65 
72  PWNAPI Result<usize>
73  sendline(_In_ std::string const& str);
74 
75 
79  PWNAPI Result<std::vector<u8>>
80  recvuntil(_In_ std::vector<u8> const& pattern);
81 
88  PWNAPI Result<std::vector<u8>>
89  recvuntil(_In_ std::string const& pattern);
90 
91 
95  PWNAPI Result<std::vector<u8>>
97 
98 
106  PWNAPI Result<usize>
107  sendafter(_In_ std::string const& pattern, _In_ std::string const& data);
108 
116  PWNAPI Result<usize>
117  sendafter(_In_ std::vector<u8> const& pattern, _In_ std::vector<u8> const& data);
118 
119 
127  PWNAPI Result<usize>
128  sendlineafter(_In_ std::string const& pattern, _In_ std::string const& data);
129 
137  PWNAPI Result<usize>
138  sendlineafter(_In_ std::vector<u8> const& pattern, _In_ std::vector<u8> const& data);
139 
140 
144  PWNAPI Result<usize>
145  peek();
146 
147 
151  PWNAPI void
153 
154 
155 protected:
156  Tube() = default;
157  ~Tube() = default;
158 
159  virtual Result<usize>
160  send_internal(_In_ std::vector<u8> const& data) = 0;
161 
162  virtual Result<std::vector<u8>>
163  recv_internal(_In_ usize size) = 0;
164 
165  virtual Result<usize>
166  peek_internal() = 0;
167 
168  std::vector<u8> m_receive_buffer;
169  std::vector<u8> m_send_buffer;
170 };
171 } // namespace Net
Generic interface that represent a tube. Tube definition (process, remote) are OS-specific.
Definition: Tube.hpp:11
PWNAPI Result< usize > sendafter(_In_ std::string const &pattern, _In_ std::string const &data)
function combining in one call recvuntil() + send()
PWNAPI Result< usize > peek()
Peek into the tube to see if any data is available.
PWNAPI Result< usize > send(std::vector< u8 > const &str)
Move data given as argument to the send buffer, tries to send.
PWNAPI Result< usize > send(std::string const &str)
Move data given as argument to the send buffer, tries to send.
PWNAPI Result< usize > sendafter(_In_ std::vector< u8 > const &pattern, _In_ std::vector< u8 > const &data)
PWNAPI void interactive()
Basic REPL.
static constexpr std::string_view INTERACTIVE_PROMPT
Default prompt.
Definition: Tube.hpp:26
Result< usize > sendline(_In_ std::vector< u8 > const &data)
Send the data (as byte vector) followed by a line separator.
static constexpr usize PIPE_DEFAULT_SIZE
Default read size from the pipe.
Definition: Tube.hpp:16
Result< std::vector< u8 > > recv(_In_ usize size=Tube::PIPE_DEFAULT_SIZE)
Read bytes from the tube, moves the read bytes to the receive buffer.
PWNAPI Result< usize > sendlineafter(_In_ std::vector< u8 > const &pattern, _In_ std::vector< u8 > const &data)
PWNAPI Result< std::vector< u8 > > recvuntil(_In_ std::string const &pattern)
PWNAPI Result< std::vector< u8 > > recvuntil(_In_ std::vector< u8 > const &pattern)
Read from tube until receiving the given pattern, and return that data.
static constexpr u8 LINE_SEPARATOR
Default line separator.
Definition: Tube.hpp:21
PWNAPI Result< usize > sendline(_In_ std::string const &str)
Send the data (as str) followed by a line separator.
PWNAPI Result< usize > sendlineafter(_In_ std::string const &pattern, _In_ std::string const &data)
Convenience function combining in one call recvuntil() + sendline()
PWNAPI Result< std::vector< u8 > > recvline()
Read from tube until receiving a line separator and return it.