test sla
This commit is contained in:
@@ -4,6 +4,8 @@ import subprocess
|
||||
import time
|
||||
import re
|
||||
import os
|
||||
import logging
|
||||
|
||||
|
||||
class Carbeat(Challenge):
|
||||
flag_location = 'flags/carbeat.txt'
|
||||
@@ -13,6 +15,16 @@ class Carbeat(Challenge):
|
||||
_SERVICE_CMD = ["docker", "exec", "-i", _CONTAINER, "/home/ctfuser/chall/mybini"]
|
||||
_HEX_RE = re.compile(r'^[0-9a-fA-F]+$')
|
||||
|
||||
def _make_logger(self):
|
||||
if not hasattr(self, 'logger') or self.logger is None:
|
||||
self.logger = logging.getLogger(self.__class__.__name__)
|
||||
if not self.logger.handlers:
|
||||
h = logging.StreamHandler()
|
||||
h.setFormatter(logging.Formatter('[%(levelname)s] %(message)s'))
|
||||
self.logger.addHandler(h)
|
||||
self.logger.setLevel(logging.INFO)
|
||||
|
||||
|
||||
def _read_container_flag(self) -> str:
|
||||
out = subprocess.run(["docker", "exec", self._CONTAINER, "cat", "/flag.txt"],
|
||||
capture_output=True, text=True)
|
||||
@@ -59,6 +71,7 @@ class Carbeat(Challenge):
|
||||
return hx
|
||||
|
||||
def distribute(self, flag):
|
||||
self._make_logger()
|
||||
try:
|
||||
os.makedirs(os.path.dirname(self.flag_location), exist_ok=True)
|
||||
with open(self.flag_location, 'w') as f:
|
||||
@@ -109,6 +122,7 @@ class Carbeat(Challenge):
|
||||
self._send_line(proc, "3")
|
||||
|
||||
def check(self):
|
||||
self._make_logger()
|
||||
try:
|
||||
with open(self.flag_location, 'r') as f:
|
||||
host_flag = f.read().strip()
|
||||
@@ -117,21 +131,36 @@ class Carbeat(Challenge):
|
||||
self.logger.info('[ok] flag parity (carbeat)')
|
||||
|
||||
proc = self._spawn()
|
||||
|
||||
self.logger.info("[1] process spawned ✅")
|
||||
|
||||
self.register(proc, "karbit", 1337)
|
||||
self.logger.info("[2] user registered ✅")
|
||||
|
||||
name = self.list_user(proc)
|
||||
assert "karbit" in name
|
||||
self.logger.info("[2] user list lookup successful ✅")
|
||||
|
||||
self.login(proc, "karbit")
|
||||
self.logger.info("[3] user login successful ✅")
|
||||
|
||||
self.bini(proc, 1, "waguri")
|
||||
self.logger.info("[4] add bini ✅")
|
||||
|
||||
self.bini(proc, 2, "0")
|
||||
self.logger.info("[5] view bini ✅")
|
||||
|
||||
waguri = self._read_until(proc, "0. edit", timeout=1.)
|
||||
assert "waguri" in waguri
|
||||
self.logger.info("[6] bini lookup successful ✅")
|
||||
|
||||
self.bini(proc, 3, "0")
|
||||
self.logger.info("[7] delete bini ✅")
|
||||
|
||||
self.logout(proc)
|
||||
self.logger.info("[8] logout ✅")
|
||||
|
||||
self.exit(proc)
|
||||
self.logger.info("[9] exit ✅")
|
||||
|
||||
try:
|
||||
proc.wait(timeout=2.0)
|
||||
|
||||
Reference in New Issue
Block a user