0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

ksnCTF writeup

Last updated at Posted at 2023-03-01

0.はじめに

こんにちは。CTFとか科オリなど色々やってるもちもちといいます。なんか見つけたので埋めていってるのですが、時間がまだあまりとれてないので随時更新していきます

1.Test Problem

FLAG_SRORGLnTh2Q5fTwu

2.Easy Cipher

ROT XIII is a simple letter substitution cipher that replaces a letter with the letter XIII letters after it in the alphabet. ROT XIII is an example of the Caesar cipher, developed in ancient Rome. Flag is FLAGSwzgxBJSAMqwxxAU. Insert an underscore immediately after FLAG.

FLAG_SwzgxBJSAMqwxxAU

3.Crawling Chaos

unya.htmlにアクセスしてF12を押すと12行目だけが異常に長いのでnode.jsで実行してみた

$(function () {
    $("form").submit(function () {
        var t = $('input[type="text"]').val();
        var p = Array(70, 152, 195, 284, 475, 612, 791, 896, 810, 850, 737, 1332, 1469, 1120, 1470, 832, 1785, 2196, 1520, 1480, 1449);
        var f = false;
        if (p.length == t.length) {
            f = true;
            for (var i = 0; i < p.length; i++)
                if (t.charCodeAt(i) * (i + 1) != p[i]) f = false;
            if (f) alert("(」・ω・)」うー!(/・ω・)/にゃー!");
        }
        if (!f) alert("No");
        return false;
    });
});

なるほど、charCodeAtはUTF-16文字コードってことに注意したらいけそうですね。実装

def str_to_utf16codepoints(s):
    bs = s.encode(encoding='utf_16_be')
    return [int.from_bytes(bs[n:n+2], 'big') for n in range(0, len(bs), 2)]

def utf16codepoints_to_str(ns):
    bs = b''.join([n.to_bytes(2, byteorder="big") for n in ns])
    s = bs.decode('utf_16_be')
    return s
A=(70, 152, 195, 284, 475, 612, 791, 896, 810, 850, 737, 1332, 1469, 1120, 1470, 832, 1785, 2196, 1520, 1480, 1449)
B=[]
for i in range(21):
    B.append(A[i]//(i+1))
print(utf16codepoints_to_str(B))

FLAG_fqpZUCoqPb4izPJE

4 Onion

そう、タマネギとは無限に皮を剥くものである

from base64!!!!!!

begin 666 <data>
51DQ!1U]&94QG4#-3:4%797I74$AU
 
end

begin 666はUuencodeなのであとは適当に変換してやればいい

FLAG_FeLgP3SiAWezWPHu

5.Login

SQLインジェクションかな?
[admin,' or 1=1 --]でログインどーん

 Congratulations!
It's too easy?
Don't worry.
The flag is admin's password.

Hint:

<?php
    function h($s){return htmlspecialchars($s,ENT_QUOTES,'UTF-8');}
    
    $id = isset($_POST['id']) ? $_POST['id'] : '';
    $pass = isset($_POST['pass']) ? $_POST['pass'] : '';
    $login = false;
    $err = '';
    
    if ($id!=='')
    {
        $db = new PDO('sqlite:database.db');
        $db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_SILENT);
        $r = $db->query("SELECT * FROM user WHERE id='$id' AND pass='$pass'");
        $login = $r && $r->fetch();
        if (!$login)
            $err = 'Login Failed';
    }
?><!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <title>q6q6q6q6q6q6q6q6q6q6q6q6q6q6q6q6</title>
  </head>
  <body>
    <?php if (!$login) { ?>
    <p>
      First, login as "admin".
    </p>
    <div style="font-weight:bold; color:red">
      <?php echo h($err); ?>
    </div>
    <form method="POST">
      <div>ID: <input type="text" name="id" value="<?php echo h($id); ?>"></div>
      <div>Pass: <input type="text" name="pass" value="<?php echo h($pass); ?>"></div>
      <div><input type="submit"></div>
    </form>
    <?php } else { ?>
    <p>
      Congratulations!<br>
      It's too easy?<br>
      Don't worry.<br>
      The flag is admin's password.<br>
      <br>
      Hint:<br>
    </p>
    <pre><?php echo h(file_get_contents('index.php')); ?></pre>
    <?php } ?>
  </body>
</html>

6.Basic is secure?

Credentials: q8:FLAG_5ux7zK2NKSH8fSGA
Wiresharkでhttpを見るとAuthorizationがbase64で暗号化されている
FLAG_5ux7zK2NKSH8fSGA

7.#!

#!/usr/bin/python

こういったやつはShebangといってUnix系システムでインタプリタを指定するやつです
FLAG_SHEBANG

8.G00913

いじいじしながら素数判定を打つ

import random
def Miller_Rabin_test(num):
    if num == 2:
        return True
    if num > 2 and num & 1 == 0:
        return False

    s, t = 0, num-1
    while t & 1 == 0:
        s, t = s+1, t >> 1
    a = random.randint(1, num-1)
    if pow(a, t, num) == 1:
        return True
    for i in range(0, s):
        if pow(a, pow(2, i) * t, num) == num-1:
            return True
    return False
a=3141592653
b="589793238462643383279502884197169399375105820974944592307816406286208998628034825342117067982148086513282306647093844609550"
for i in range(100):
    if Miller_Rabin_test(a):
        print(a)
        exit()
    a%=10**9
    a*=10
    a+=int(b[i])

FLAG_Q20_5926535897

9 Math II

にぶたん

left=1
right=10**41
x = 2748040023408750324411119450523386950660946398855386842074606380418316981389557916980086140301887947706700698930830779678048474531538039134089675000612962004189001422715316147779554460684462041893073445562829316520071658956471592707597247194589999870235577599858641217209525243986680999448565468816434633441308131788183291153809253610695081752296732033298647222814340913466738465892791206393936089466068684809286651197884210187525269355913763182559833600649423167126622527203197940618965341674710993871930168655984019611567024681974446413864111651893113475795042753452042221938667445789706741508160949598322950403760355305740757495122850819958219745478009476321531997688864567881328571570240278649150057863614800304034452842380274161491817926949213762740941829027657311016236224840157689532838274458699038989430527152474540367086746579688987076042252804910459873636444778218434530247647760637770881658596016745610672707638583665201858035977485748775481448417394363801163664632527695106599930657132405666766730530997168969743603771751166591137309462845077320233889570871715682231576283485837079838925927845291565664213349164253238166525895494203520538861102027123057706413048503799598270037162337386882901940037500301040636118696723417952777083334146545991127148023661461455142653367976629308434919237639329808504561590505864983890552051987234096577849288536293631380950881787840319976968198704697701966146561843819563765280293823120028941691560894722032503932540560461794190408016359786029679686957711035845785762377768203676919060935155382104877926736292611130243057909501332528103700463961697932230444978571571548190911155741113324573679444638703192583211952316173122745153529542339170631749363019742630339456502772150867703497326010832217054307087826776870481852284816747574983354077170761286175754243223519482572371717625453405597596790583499145036350302955327521461648262537855645876387858201576107385450844609238327605056916243564458120595540013872075267316304999752934829122583429168665162743589578036716137649553856654996867605565582594039606555708509284616434305172100068285925706963351193710675088846623856567419346569873886366829228933416064828304824833588800700991940600359503453201939139663042787644390810036292415117714919711827630953170559057272633043896443339064006637234499569232762828723613158050896065355005775876910820958296537497557737916521798848004761708690607167573807307291510879396794861418856342383200817566360552405183866698509354047737422523253071467100174078467454351746681775690022510266842064132386305358891086764558955802257688899610117102582837343655907837234028334304769930810792079059216436489942124896722072971246781926084943216581585837400274934104255861076781834022322597318553478829221018993823759479304536464719195824731739557957722610850860725276329731096193041588880149698625007746958307472328762247329346952956782896672291984502790479223886842985800649168009891087704339671376795754679245964575179873102014722210341771266309855717402003098724600141420936602986387680283404929020457247001371544838792904086327642729822000980710278752669990211765608002907900832262843253793831541691706704836397397798869236939393204666502455311086553874765248631328418556164635889080357612074921368044611251307530838475840480894307375072202500636365832958938363048173011687247738236161480446422712858040552310006617829659443118541556912488329721272939472554467384944920030182974546889304443711910957344160175437149714520561879951921970795705645045936350875827028675689840953101114431720413756855193291198455863087675930604549263160397353363504597829924339064422377323361781720524799661393081986371074530022532621955945720583925291264598924971169093688390536693144593482790588893095052569365154072722966434676949346037949263628957665599420417719951187489606010866702371368012263032537375401145460592536898818245350468847674995676417425737655723761467908866712060720593684978725896677308273

while right-left>1:
    mid=(right+left)//2
    ok=mid**101
    if ok<x:
        left=mid
    elif ok>x:
        right=mid
    else:
        print(mid)
        exit()
print(mid)

FLAG_545783032743911043438387247245888260273

10.Math I

from Crypto.Util.number import long_to_bytes

e=65537
n = 1517330236262917595314610888889322115651087080826711948897066340883208205571592392362650858571076247939805436226544833224526137582834770402681005343930059463684528957271778199162575053306238099823295117697031968370690372250916935800738698142103275969223264184374648246277564306900886005299731265812255274723175925185522344831066577166867786835955092059346244885587228196357297758371381557924676260190209536670230008561217008649261974735505203813478978893582292682827884118215872470401293272325715864815977064075988643101088355047954735427424641386870772845440782632933485165110172437511822736907550777817722248753671107339823410418938404382732079381329288400012929311347390423061254658780185245562668131009832293474920208834795460061115101364091252176594144096675899952570380792978037217747311595899301451192342027799533264325948876556110474850761538179748318187805312451895898751337975457949549497666542175077894987697085521882531938339334715190663665300179658557458036053188152532948734992896239950564081581184284728802682982779186068791931259198917308153082917381616147108543673346682338045309449569430550618884202465809290850964525390539782080230737593560891353558335337408957948041667929154230334506735825418239563481028126435029
c = 225549592628492616152632265482125315868911125659971085929712296366214355608049224179339757637982541542745010822022226409126123627804953064072055667012172681551500780763483172914389813057444669314726404135978565446282309019729994976815925850916487257699707478206132474710963752590399332920672607440793116387051071191919835316845827838287954541558777355864714782464299278036910958484272003656702623646042688124964364376687297742060363382322519436200343894901785951095760714894439233966409337996138592489997024933882003852590408577812535049335652212448474376457015077047529818315877549614859586475504070051201054704954654093482056493092930700787890579346065916834434739980791402216175555075896066616519150164831990626727591876115821219941268309678240872298029611746575376322733311657394502859852213595389607239431585120943268774679785316133478171225719729917877009624611286702010936951705160870997184123775488592130586606070277173392647225589257616518666852404878425355285270687131724258281902727717116041282358028398978152480549468694659695121115046850718180640407034795656480263573773381753855724693739080045739160297875306923958599742379878734638341856117533253251168244471273520476474579680250862738227337561115160603373096699944163
p = 34111525225922333955113751419357677129436029651245533697825114748126342624744832960936498161825269430327019858323450578875242014583535842110912370431931233957939950911741013017595977471949767235426490850284286661592357779825212265055931705799916913817655743434497422993498931394618832741336247426815710164342599150990608143637331068220244525541794855651643135012846039439355101027994945120698530177329829213208761057392236875366458197098507252851244132455996468628957560178868724310000317011912994632328371761486669358065577269198065792981537378448324923622959249447066754504943097391628716371245206444816309511381323
q = 44481453884385518268018625442920628989497457642625668259648790876723318635861137128631112417617317160816537010595885992856520476731882382742220627466006460645416066646852266992087386855491152795237153901319521506429873434336969666536995399866125781057768075533560120399184566956433129854995464893265403724034960689938351450709950699740508459206785093693277541785285699733873530541918483842122691276322286810422297015782658645129421043160749040846216892671031156465364652681036828461619272427318758098538927727392459501761203842363017121432657534770898181975532066012149902177196510416802134121754859407938165610800223
d=pow(e,-1,(p-1)*(q-1))
m=pow(c,d,n)
print(long_to_bytes(m))

FLAG_NbZ6gQeKDMVFJMaU

11.Programming

cppに見せかけたwhitespaceって言語
whitespace IDEでぐぐったら出てきた
pinの値入力しろ言われたので複数回pushされてたでかい右の数字を入れた。やったー

http://vii5ard.github.io/whitespace/
image.png

FLAG_EmTx6FTbGLieiMcA

12.USB flash drive

ディスクイメージ渡されたのでforemost打って

image.png
こんなの見つけてfls打って

r/r 4-128-4:    $AttrDef
r/r 8-128-2:    $BadClus
r/r 8-128-1:    $BadClus:$Bad
r/r 6-128-4:    $Bitmap
r/r 7-128-1:    $Boot
d/d 11-144-4:   $Extend
r/r 2-128-1:    $LogFile
r/r 0-128-1:    $MFT
r/r 1-128-1:    $MFTMirr
r/r 9-128-8:    $Secure:$SDS
r/r 9-144-11:   $Secure:$SDH
r/r 9-144-5:    $Secure:$SII
r/r 10-128-1:   $UpCase
r/r 3-128-3:    $Volume
r/r 35-128-1:   Carl Larsson Brita as Iduna.jpg
r/r 37-128-1:   Mona Lisa.jpg
r/r 38-128-1:   The Great Wave off Kanagawa.jpg
-/r * 36-128-1: Liberty Leading the People.jpg
-/r * 36-128-4: Liberty Leading the People.jpg:00
-/r * 36-128-5: Liberty Leading the People.jpg:01
-/r * 36-128-6: Liberty Leading the People.jpg:02
-/r * 36-128-7: Liberty Leading the People.jpg:03
-/r * 36-128-8: Liberty Leading the People.jpg:04
-/r * 36-128-9: Liberty Leading the People.jpg:05
-/r * 36-128-10:        Liberty Leading the People.jpg:06
V/V 256:        $OrphanFiles

怪しい消されたファイルをicatで見てみる。00-05まで合わせたのがフラグ
FLAG_qazyetF6icoWCvjN

13.Reserved

ググったらperlが出てきた

 length q chr uc and print chr ord uc qw q flock q and print chr oct ord q or no and print chr ord uc q each ne and print chr ord uc qw q gt q and print chr oct hex ord uc q my m and print chr ord uc q each ne and print chr ord qw q sin q and print chr oct ord uc q each le and print chr length q q splice srand getservbyname setnetent ne reset endprotoent foreach scalar rewinddir cos setnetent not else getprotobyname q and print chr ord qw q ge q and print chr ord uc q eval le and print chr ord uc qw q sin q and print chr ord uc qw q no q and print chr ord qw q use q and print chr ord q mkdir m and print chr ord q each le and print chr ord q pop and print chr oct ord q open no and print chr ord q eval le and print chr ord q eval le and print chr oct hex ord uc q gt log and print chr ord q q eq and print chr ord q q eq and print chr ord q q q and print chr ord qq q q and print chr ord uc q lt eval and print chr ord q chr lc and print chr ord q map m and print chr ord qw q ne q and print chr ord q mkdir m and print chr ord q q q and print chr ord q my alarm and print chr ord q pop and print chr ord qw q uc q and print chr oct oct ord uc qw q bind q and print chr ord q q eq and print chr ord q split s and print chr ord q open do and print chr ord q ge log and print chr ord qw q not q and print chr ord q oct no and print chr ord q xor x and print chr ord qw q die q and print chr ord q ne sin and print chr oct oct ord uc qw q fork q

FLAG_As5zgVSNukaoJvvZ Thank you, ppencode.

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?