Browse Source

adapted for slashroot 2019

master
myitinos 8 months ago
parent
commit
689693df2b
10 changed files with 88 additions and 95 deletions
  1. 0
    10
      .drone.yml
  2. 2
    0
      .start.sh
  3. 4
    4
      Dockerfile
  4. 1
    1
      Makefile
  5. 0
    14
      build-image.sh
  6. 10
    0
      docker-compose.yml
  7. 1
    1
      flag.txt
  8. 2
    2
      src/system/betatest.cpp
  9. 68
    63
      src/system/memory.cpp
  10. BIN
      version002

+ 0
- 10
.drone.yml View File

@@ -1,10 +0,0 @@
1
-pipeline:
2
-  build-docker:
3
-    image: docker:18.06.1-ce
4
-    volumes:
5
-      - /var/run/docker.sock:/var/run/docker.sock
6
-    commands:
7
-      - chmod +x ./build-image.sh
8
-      - ./build-image.sh
9
-    when:
10
-event: [push]

+ 2
- 0
.start.sh View File

@@ -0,0 +1,2 @@
1
+#!/bin/bash
2
+(socat TCP-LISTEN:20202,reuseaddr,fork EXEC:/chall/version002,su=nobody)

+ 4
- 4
Dockerfile View File

@@ -1,5 +1,5 @@
1
-# Use ubuntu 16.04
2
-FROM ubuntu:16.04
1
+# Use ubuntu 19.04
2
+FROM ubuntu:latest
3 3
 EXPOSE 20202
4 4
 RUN apt-get update
5 5
 
@@ -15,6 +15,7 @@ WORKDIR /chall
15 15
 # Secure ENV
16 16
 COPY flag.txt .
17 17
 COPY version002 .
18
+COPY .start.sh /var/tmp/
18 19
 
19 20
 RUN echo 'alias kill="echo no kill please!"' >> ~/.bashrc
20 21
 RUN chmod 700 /tmp /usr/bin/* /bin/* /dev/shm
@@ -22,9 +23,8 @@ RUN chmod 700 /tmp /usr/bin/* /bin/* /dev/shm
22 23
 
23 24
 RUN chown root:ksl /chall/version002
24 25
 RUN chmod 775 /chall/version002
26
+RUN chmod 775 /var/tmp/.start.sh
25 27
 
26 28
 # Run Service
27 29
 
28
-RUN echo '#!/bin/bash'"\n(socat TCP-LISTEN:20202,reuseaddr,fork EXEC:"/chall/version002,su=nobody")" > /var/tmp/.start.sh && chmod +x /var/tmp/.start.sh
29
-
30 30
 CMD ["/var/tmp/.start.sh"]

+ 1
- 1
Makefile View File

@@ -1,7 +1,7 @@
1 1
 COMPILER=g++
2 2
 #FLAGS=-g -I. -pedantic -Wall -Wextra -Wcast-align -Wcast-qual -Wctor-dtor-privacy -Wdisabled-optimization -Wformat=2 -Winit-self -Wlogical-op -Wmissing-declarations -Wmissing-include-dirs -Wnoexcept -Wold-style-cast -Woverloaded-virtual -Wredundant-decls -Wshadow -Wsign-conversion -Wsign-promo -Wstrict-null-sentinel -Wstrict-overflow=5 -Wswitch-default -Wundef -Werror -Wno-unused
3 3
 #FLAGS=-g -I.
4
-FLAGS=-I.
4
+FLAGS=-s -I.
5 5
 O_DIR=obj
6 6
 
7 7
 CLASS_DIR=src/class

+ 0
- 14
build-image.sh View File

@@ -1,14 +0,0 @@
1
-#!/bin/sh
2
-set -e
3
-set -o xtrace
4
-
5
-IMAGE_NAME=hack-the-game-v002
6
-
7
-# clean old images
8
-OLD_IMAGES=$(docker images $IMAGE_NAME -q --no-trunc)
9
-if [ -n "${OLD_IMAGES}" ]; then
10
-  docker rmi -f ${OLD_IMAGES};
11
-fi
12
-
13
-#Build Images
14
-docker build . -t $IMAGE_NAME

+ 10
- 0
docker-compose.yml View File

@@ -0,0 +1,10 @@
1
+version: "2"
2
+
3
+services:
4
+  main:
5
+    build: .
6
+    container_name: "htg2"
7
+    network_mode: "bridge"
8
+    restart: on-failure
9
+    ports:
10
+      - "30313:20202"

+ 1
- 1
flag.txt View File

@@ -1 +1 @@
1
-GKSK{H0w_d1d_I_n0t_real1ze_such_4_s7up1d_m1sT4k3}
1
+SlashRootCTF{Th47_15_d3f1Nit3ly_a_5tup1D_m1sT4kE}

+ 2
- 2
src/system/betatest.cpp View File

@@ -1,9 +1,9 @@
1 1
 #include "src/system/betatest.hpp"
2 2
 
3 3
 
4
-std::string BetaTest::betaFlag = "4re_Y0u_53ri0usly_checking_f0r_b3t4_t3sT?";
4
+std::string BetaTest::betaFlag = "7h1s_i5_n0t_a_b3t4_tE5t_k3y";
5 5
 
6 6
 bool BetaTest::check(std::string input)
7 7
 {
8
-    return input.compare("GKSK{" + betaFlag + "}") == 0;
8
+    return input.compare("SlashRootCTF{" + betaFlag + "}") == 0;
9 9
 }

+ 68
- 63
src/system/memory.cpp View File

@@ -4,32 +4,33 @@
4 4
 #include <string>
5 5
 #include <cstring>
6 6
 
7
-static const std::string base64_chars = 
8
-             "abcdefghijklmnopqrstuvwxyz"
9
-             "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
10
-             "0123456789+/";
7
+static const std::string base64_chars =
8
+    "s1XWgtaLvfyEeYUi42Mo36NR9DKrVjbTpPuwHc5lA8dC0OSxzknm7qGJBIZFQh+/";
11 9
 
12
-
13
-static inline bool is_base64(unsigned char c) {
10
+static inline bool is_base64(unsigned char c)
11
+{
14 12
   return (isalnum(c) || (c == '+') || (c == '/'));
15 13
 }
16 14
 
17
-std::string base64_encode(unsigned char const* bytes_to_encode, unsigned int in_len) {
15
+std::string base64_encode(unsigned char const *bytes_to_encode, unsigned int in_len)
16
+{
18 17
   std::string ret;
19 18
   int i = 0;
20 19
   int j = 0;
21 20
   unsigned char char_array_3[3];
22 21
   unsigned char char_array_4[4];
23 22
 
24
-  while (in_len--) {
23
+  while (in_len--)
24
+  {
25 25
     char_array_3[i++] = *(bytes_to_encode++);
26
-    if (i == 3) {
26
+    if (i == 3)
27
+    {
27 28
       char_array_4[0] = (char_array_3[0] & 0xfc) >> 2;
28 29
       char_array_4[1] = ((char_array_3[0] & 0x03) << 4) + ((char_array_3[1] & 0xf0) >> 4);
29 30
       char_array_4[2] = ((char_array_3[1] & 0x0f) << 2) + ((char_array_3[2] & 0xc0) >> 6);
30 31
       char_array_4[3] = char_array_3[2] & 0x3f;
31 32
 
32
-      for(i = 0; (i <4) ; i++)
33
+      for (i = 0; (i < 4); i++)
33 34
         ret += base64_chars[char_array_4[i]];
34 35
       i = 0;
35 36
     }
@@ -37,26 +38,25 @@ std::string base64_encode(unsigned char const* bytes_to_encode, unsigned int in_
37 38
 
38 39
   if (i)
39 40
   {
40
-    for(j = i; j < 3; j++)
41
+    for (j = i; j < 3; j++)
41 42
       char_array_3[j] = '\0';
42 43
 
43
-    char_array_4[0] = ( char_array_3[0] & 0xfc) >> 2;
44
+    char_array_4[0] = (char_array_3[0] & 0xfc) >> 2;
44 45
     char_array_4[1] = ((char_array_3[0] & 0x03) << 4) + ((char_array_3[1] & 0xf0) >> 4);
45 46
     char_array_4[2] = ((char_array_3[1] & 0x0f) << 2) + ((char_array_3[2] & 0xc0) >> 6);
46 47
 
47 48
     for (j = 0; (j < i + 1); j++)
48 49
       ret += base64_chars[char_array_4[j]];
49 50
 
50
-    while((i++ < 3))
51
+    while ((i++ < 3))
51 52
       ret += '=';
52
-
53 53
   }
54 54
 
55 55
   return ret;
56
-
57 56
 }
58 57
 
59
-std::string base64_decode(std::string const& encoded_string) {
58
+std::string base64_decode(std::string const &encoded_string)
59
+{
60 60
   int in_len = encoded_string.size();
61 61
   int i = 0;
62 62
   int j = 0;
@@ -64,15 +64,18 @@ std::string base64_decode(std::string const& encoded_string) {
64 64
   unsigned char char_array_4[4], char_array_3[3];
65 65
   std::string ret;
66 66
 
67
-  while (in_len-- && ( encoded_string[in_] != '=') && is_base64(encoded_string[in_])) {
68
-    char_array_4[i++] = encoded_string[in_]; in_++;
69
-    if (i ==4) {
70
-      for (i = 0; i <4; i++)
67
+  while (in_len-- && (encoded_string[in_] != '=') && is_base64(encoded_string[in_]))
68
+  {
69
+    char_array_4[i++] = encoded_string[in_];
70
+    in_++;
71
+    if (i == 4)
72
+    {
73
+      for (i = 0; i < 4; i++)
71 74
         char_array_4[i] = base64_chars.find(char_array_4[i]);
72 75
 
73
-      char_array_3[0] = ( char_array_4[0] << 2       ) + ((char_array_4[1] & 0x30) >> 4);
76
+      char_array_3[0] = (char_array_4[0] << 2) + ((char_array_4[1] & 0x30) >> 4);
74 77
       char_array_3[1] = ((char_array_4[1] & 0xf) << 4) + ((char_array_4[2] & 0x3c) >> 2);
75
-      char_array_3[2] = ((char_array_4[2] & 0x3) << 6) +   char_array_4[3];
78
+      char_array_3[2] = ((char_array_4[2] & 0x3) << 6) + char_array_4[3];
76 79
 
77 80
       for (i = 0; (i < 3); i++)
78 81
         ret += char_array_3[i];
@@ -80,14 +83,16 @@ std::string base64_decode(std::string const& encoded_string) {
80 83
     }
81 84
   }
82 85
 
83
-  if (i) {
86
+  if (i)
87
+  {
84 88
     for (j = 0; j < i; j++)
85 89
       char_array_4[j] = base64_chars.find(char_array_4[j]);
86 90
 
87 91
     char_array_3[0] = (char_array_4[0] << 2) + ((char_array_4[1] & 0x30) >> 4);
88 92
     char_array_3[1] = ((char_array_4[1] & 0xf) << 4) + ((char_array_4[2] & 0x3c) >> 2);
89 93
 
90
-    for (j = 0; (j < i - 1); j++) ret += char_array_3[j];
94
+    for (j = 0; (j < i - 1); j++)
95
+      ret += char_array_3[j];
91 96
   }
92 97
 
93 98
   return ret;
@@ -95,47 +100,47 @@ std::string base64_decode(std::string const& encoded_string) {
95 100
 
96 101
 Player *Memory::loadFromCode(std::string code)
97 102
 {
98
-    code = base64_decode(code);
99
-    char playerName[16] = {0};
100
-    int playerHP = 0;
101
-    int playerAtk = 0;
102
-    int playerDef = 0;
103
-    int playerLevel = 0;
104
-    int playerExp = 0;
105
-
106
-    int result = sscanf(code.c_str(),
107
-                        "PlayerLevel=%d;PlayerExp=%d;PlayerHP=%d;PlayerAtk=%d;PlayerDef=%d;PlayerName=%15s",
108
-                        &playerLevel,
109
-                        &playerExp,
110
-                        &playerHP,
111
-                        &playerAtk,
112
-                        &playerDef,
113
-                        playerName);
114
-
115
-    std::string playerTrueName = playerName;
116
-
117
-    if (result == 6)
118
-    {
119
-        return new Player(playerTrueName, playerHP, playerAtk, playerDef, playerLevel, playerExp);
120
-    }
121
-    else
122
-    {
123
-        return nullptr;
124
-    }
103
+  code = base64_decode(code);
104
+  char playerName[16] = {0};
105
+  int playerHP = 0;
106
+  int playerAtk = 0;
107
+  int playerDef = 0;
108
+  int playerLevel = 0;
109
+  int playerExp = 0;
110
+
111
+  int result = sscanf(code.c_str(),
112
+                      "PlayerLevel=%d;PlayerExp=%d;PlayerHP=%d;PlayerAtk=%d;PlayerDef=%d;PlayerName=%15s",
113
+                      &playerLevel,
114
+                      &playerExp,
115
+                      &playerHP,
116
+                      &playerAtk,
117
+                      &playerDef,
118
+                      playerName);
119
+
120
+  std::string playerTrueName = playerName;
121
+
122
+  if (result == 6)
123
+  {
124
+    return new Player(playerTrueName, playerHP, playerAtk, playerDef, playerLevel, playerExp);
125
+  }
126
+  else
127
+  {
128
+    return nullptr;
129
+  }
125 130
 }
126 131
 
127 132
 std::string Memory::saveToCode(Player *player)
128 133
 {
129
-    char code[256];
130
-    snprintf(code, sizeof(code),
131
-             "PlayerLevel=%d;PlayerExp=%d;PlayerHP=%d;PlayerAtk=%d;PlayerDef=%d;PlayerName=%s",
132
-             player->getLevel(),
133
-             player->getExp(),
134
-             player->getMaxHP(),
135
-             player->getAtk(),
136
-             player->getDef(),
137
-             player->getName().c_str());
138
-
139
-    return base64_encode(reinterpret_cast<unsigned char *>(code),
140
-                         strlen(code));
134
+  char code[256];
135
+  snprintf(code, sizeof(code),
136
+           "PlayerLevel=%d;PlayerExp=%d;PlayerHP=%d;PlayerAtk=%d;PlayerDef=%d;PlayerName=%s",
137
+           player->getLevel(),
138
+           player->getExp(),
139
+           player->getMaxHP(),
140
+           player->getAtk(),
141
+           player->getDef(),
142
+           player->getName().c_str());
143
+
144
+  return base64_encode(reinterpret_cast<unsigned char *>(code),
145
+                       strlen(code));
141 146
 }

BIN
version002 View File


Loading…
Cancel
Save