もちもちブログ

競技プログラミングやCTFをしている高1です

CTFの自分向けテクニック。随時更新中

 まず

高校1年のもちもちです。セキュリティキャンプ全国大会2021やCODE BLUE2022に参加しててモチベが爆上がりしてるのでCTFの勉強をしています。自分が問題を解いていく中で典型度が高そうと思ったことを随時更新していきます

Network

  • pcapが与えられたらとりあえずWiresharkでしばけ

  • "変"なファイルが答えになることが多い

  • パケット数

  • プロトコルを見ろ

  • 401 Unauthorized 認証失敗

  • 200 認証成功

事故調査

ペンテスト

  • root
    • sudo -l でroot権限のあるやつ表示

僕のsetting.json

{
    "editor.formatOnType": true,
    "editor.formatOnSave": true,
    "C_Cpp.clang_format_style": "{IndentWidth: 4, ColumnLimit: 120, AllowShortFunctionsOnASingleLine: 'None'}",
    "background.customImages": [
        "file://c:/Users/name/OneDrive/画像/Saved Pictures/uta.jpg"
    ],
    "background.style": {
        "content": "''",
        "pointer-events": "none",
        "position": "absolute",
        "width": "100%",
        "height": "120%",
        "z-index": "99999",
        "background-repeat": "no-repeat",
        "background-size": "cover",
        "opacity": 0.2
    },
    "background.useFront": false,
    "background.useDefault": false,
    "background.loop": false,
    // customImagesは環境によってパスが異なるため私は同期対象外にしている
    "settingsSync.ignoredSettings": [
        "background.customImages"
    ],
    "files.associations": {
        "random": "cpp",
        "array": "cpp",
        "atomic": "cpp",
        "bitset": "cpp",
        "chrono": "cpp",
        "complex": "cpp",
        "condition_variable": "cpp",
        "cwchar": "cpp",
        "deque": "cpp",
        "list": "cpp",
        "exception": "cpp",
        "fstream": "cpp",
        "functional": "cpp",
        "future": "cpp",
        "initializer_list": "cpp",
        "iosfwd": "cpp",
        "istream": "cpp",
        "mutex": "cpp",
        "new": "cpp",
        "ostream": "cpp",
        "ratio": "cpp",
        "scoped_allocator": "cpp",
        "shared_mutex": "cpp",
        "sstream": "cpp",
        "stdexcept": "cpp",
        "streambuf": "cpp",
        "thread": "cpp",
        "tuple": "cpp",
        "type_traits": "cpp",
        "typeindex": "cpp",
        "utility": "cpp",
        "valarray": "cpp",
        "iostream": "cpp",
        "any": "cpp",
        "bit": "cpp",
        "*.tcc": "cpp",
        "cctype": "cpp",
        "cfenv": "cpp",
        "charconv": "cpp",
        "cinttypes": "cpp",
        "clocale": "cpp",
        "cmath": "cpp",
        "codecvt": "cpp",
        "csetjmp": "cpp",
        "csignal": "cpp",
        "cstdarg": "cpp",
        "cstddef": "cpp",
        "cstdint": "cpp",
        "cstdio": "cpp",
        "cstdlib": "cpp",
        "cstring": "cpp",
        "ctime": "cpp",
        "cuchar": "cpp",
        "cwctype": "cpp",
        "forward_list": "cpp",
        "map": "cpp",
        "set": "cpp",
        "unordered_map": "cpp",
        "unordered_set": "cpp",
        "vector": "cpp",
        "algorithm": "cpp",
        "iterator": "cpp",
        "memory": "cpp",
        "memory_resource": "cpp",
        "numeric": "cpp",
        "optional": "cpp",
        "regex": "cpp",
        "string": "cpp",
        "string_view": "cpp",
        "system_error": "cpp",
        "iomanip": "cpp",
        "limits": "cpp",
        "typeinfo": "cpp",
        "variant": "cpp"
    },
    "C_Cpp.errorSquiggles": "Enabled",
    "editor.formatOnPaste": true,
}

アルファベットと数字の互換

コンテスト中時々出てくる、大文字から小文字への変換や、アルファベットを数字に変えたりするやつのまとめです まず数字からアルファベット

#include <bits/stdc++.h>
using namespace std;
signed main()
{
  //3番目のアルファベットを出力する
  int p = 3;
  char ans = char('a' + p - 1);
  cout << ans << endl;
}

実行結果

$ g++ -o sample sample.cpp
$ ./sample
c

次に数字からアルファベットへの変換です。さっきやったことの逆をするだけですね

#include <bits/stdc++.h>
using namespace std;
signed main()
{
  //cが何番目のアルファベットかを出力する
  char p = 'c';
  int ans = p - 'a' + 1;
  cout << ans << endl;
}

実行結果

$ g++ -o sample sample.cpp
$ ./sample
3

最後に大文字と小文字の変換です

#include <bits/stdc++.h>
using namespace std;
signed main()
{
  //cを大文字に変換
  char p = 'c';
  cout << char(p - 32) << endl;
  //Cを小文字に変換
  char q = 'C';
  cout << char(q + 32) << endl;
}

実行結果

$ g++ -o sample sample.cpp
$ ./sample
C
c

GitHubはじめた話

ロボットの大会でコード書いてて必要を感じたのでついに僕もGitHubデビューしました。 そういや全国統一高校生テストの高3部門が帰ってきてたなどれどれ... f:id:motimotipurinn:20211111232244p:plain

あほしね

git-scm.com

まずはこっから、windowsにGitをぶちこむ。ちな僕はインストールの際なにも見ずにずっとnext押してたせいでもう一回やる羽目になったので良い子のみなさんはちゃんとやろうね。 github.co.jp 次にGitHubのアカウントをつくる。僕はすでにこれはやってたのでパス。メアドと名前入れるだけ

github.com 次、適当に命名するだけで何もいじらなくてOK。ここでは仮に"github_sample"にしておく。そしたらQuick setupって画面が出てくるので残しておきましょうあとで使うので これができたらさっきインストールしたGItにくっついとるgit bashってものを開いて

$ mkdir github_sample
$ cd github_sample
$ git init

の3を実行する。そしたら適当なファイルを作ってgithub_sampleフォルダにぶちこむ。ここではHello.cppとしましょうか。

#include <bits/stdc++.h>
using namespace std;
signed main()
{
  cout << "Hello Github" << endl;
}

そしたらgit bashにまた戻って

$ git add Hello.cpp
$ git commit -m "My new gear!"
$ git remote add origin (さっきのQuick setupに書かれてあるURLをコピペ)
$ git push origin master

すると f:id:motimotipurinn:20211111231710p:plain このようにGithub上にHello.cppを載せられたことがわかります。 まとめ 以上の動作で自由にファイルをGitHubに乗せれるようになります。バージョン管理とかはおいおい開発が進むにつれて勉強していくので今日はこのへんで。最後まで読んでくださってありがとうございました~

Virus Tree 2

atcoder.jp

DFSをしながらK色で木を塗っていく。x,yの距離が2以下ならば色が異なるということで頂点を一つ決めた時に、それの親と親に隣接するやつ以外で塗ればいいことがわかる。

#include <bits/stdc++.h>
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#define ll long long
#define int long long
#define REP(i, n) for (long long i = 0; i < (int)(n); i++)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(a) (a).begin(), (a).end()
#define fore(i, a) for (auto &i : a)
using namespace std;
using in = int;
using vin = vector<in>;
const ll MOD = 1e9 + 7;
in N, K;
vin E[101010];
int dfs(in cu, in pa, in rest)
{
  in res = rest;
  in my = 1;
  if (cu > 0)
    my++;
  fore(to, E[cu]) if (to != pa)
  {
    res = (res * dfs(to, cu, K - my)) % MOD;
    my++;
  }
  return res;
}
signed main()
{
  cin >> N >> K;
  rep(i, N - 1)
  {
    in a, b;
    cin >> a >> b;
    a--;
    b--;
    E[a].push_back(b);
    E[b].push_back(a);
  }
  cout << dfs(0, -1, K);
}