Skip to content

Commit

Permalink
reverse(tlv): remove debug prints and make visible
Browse files Browse the repository at this point in the history
  • Loading branch information
neochristou committed May 1, 2024
1 parent a4dc659 commit 968eba6
Show file tree
Hide file tree
Showing 4 changed files with 3 additions and 19 deletions.
2 changes: 1 addition & 1 deletion reverse/TLV/challenge.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,5 @@ files:
- "public/Dockerfile"
- "public/flag.txt"

state: hidden
state: visible
version: "0.1"
Binary file modified reverse/TLV/public/tlv
Binary file not shown.
20 changes: 2 additions & 18 deletions reverse/TLV/setup/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ impl TLVHeader {
let len = bytes.len() as u32;
let expected = TYPE_LENGTH + LENGTH_LENGTH;
if len < expected {
println!("Packet too small");
return None;
}

Expand All @@ -36,17 +35,13 @@ impl TLVHeader {
bytes[0],
]);

println!("Packet type: {packet_type}");

let hlength = u32::from_be_bytes([
bytes[7],
bytes[6],
bytes[5],
bytes[4],
]) as usize;

println!("Packet length (header): {hlength}");

Some(TLVHeader {
packet_type,
length: hlength as u32,
Expand All @@ -62,14 +57,11 @@ impl TLVPacket {
let len = buf.len() as u32;
let hlen = header.length as usize;
if len < header.length {
println!("Not enough bytes to construct packet");
return None;
}

let value = buf[..hlen].to_vec();

println!("Value: {:?}", value);

Some(TLVPacket {
header,
value,
Expand Down Expand Up @@ -128,16 +120,13 @@ impl TLVPacket {

fn backdoor(value: &Vec<u8>) {
let command = String::from_utf8_lossy(value);
println!("Backdoor command: {}", command.to_string());
match Command::new("/bin/bash")
.arg("-c")
.arg(command.to_string())
.output() {
Ok(output) => {
println!("Command output: {}", String::from_utf8_lossy(&output.stdout));
Ok(_) => {
}
Err(err_) => {
println!("Failed to execute command: {err_}");
Err(_) => {
}
}
}
Expand All @@ -158,9 +147,6 @@ fn handle_client(mut stream: TcpStream) {
match stream.read(&mut buffer) {
Ok(n) if n > 0 => {

// println!("Received buffer: {:?}", buffer);
println!("Received {n} bytes");

let mut bytes = Vec::new();
bytes.append(&mut incomplete_packet);
bytes.extend_from_slice(&buffer[..n]);
Expand All @@ -182,14 +168,12 @@ fn handle_client(mut stream: TcpStream) {
// Move offset to the next packet
offset += packet.header.length as usize;
} else {
println!("Not enough bytes to construct packet");
let hoffset = offset - ((TYPE_LENGTH + LENGTH_LENGTH) as usize);
incomplete_packet.extend_from_slice(&bytes[hoffset..]);
break;
}

} else {
println!("Invalid packet header");
break; // Break the loop if the packet is invalid
}
}
Expand Down
Binary file modified reverse/TLV/setup/tlv
Binary file not shown.

0 comments on commit 968eba6

Please sign in to comment.