1. 程式人生 > 其它 >treeMap 的多種遍歷方式以及比較器和comparable的實現

treeMap 的多種遍歷方式以及比較器和comparable的實現

技術標籤:web

HECTF2020

做了misc、Web和密碼的題,總結一下學到的東西。
WEB
簽到有手就行,忘記密碼連在burp上爆破就行了。
ezphp

<?php 
highlight_file(__file__);
include('flag.php'); 
$string_1 = $_GET['str1']; 
$string_2 = $_GET['str2']; 


if($_GET['param1']!==$_GET['param2']&&md5($_GET['param1'])===md5($_GET['param2'])){


        if
(is_numeric($string_1)){ $md5_1 = md5($string_1); $md5_2 = md5($string_2); if($md5_1 != $md5_2){ $a = strtr($md5_1, 'cxhp', '0123'); $b = strtr($md5_2, 'cxhp', '0123'); if($a == $b){ echo $flag
; } else { die('you are close'); } } else { die("md5 is wrong"); } } else { die('str1 not number'); } } else { die('you are wrong!'
); } ?>

程式碼審計題,首先看程式碼

if($_GET['param1']!==$_GET['param2']&&md5($_GET['param1'])===md5($_GET['param2']))

首先要明白php弱型別比較和強型別比較的區別,!=和這種是弱比較,比較型別可以不同。要使$a == $b,只需要型別轉換後 $a 等於 $b即可;要使$a=== $b,則不但需要 $a 等於 $b,並且需要它們的型別也相同。可以明確的看到,==會在比較的時候進行型別轉換的比較。
可以看到原始碼裡都是強型別比較,所以在比較時不做型別轉換,直接字串比較。所以要用到md5遇見陣列報錯的條件,返回null,null===null即可繞過。
進入後還有$String_1為整數的條件,string1和string2的md5值還不相同,換了cxhp為0123後又弱相等了,說明原來是ce和0e,後來是0e和0e。簡單寫個指令碼

<?php
$count= 0;
for($i = 1; $i <= 100000000; $i++) {
   $md5 = strtr(md5($i),'cxhp', '0123');
   if(preg_match('/^0e\d+$/', $md5)) {
       echo $i ." " . md5($i) . "<br>";
       $count++;
   }
   if ($count == 2) {
       break;
   }
}
?>

最終payload為

?param1[]=1&param2[]=2&str1=9427417&str2=9081940

Crypto
不說人話
開啟檔案後發現是這麼一串

… … … .!!! .?.. … … …?. ?!.?. … … …
!.!!! !!!. !!! .?.. … .!!! .?.. … ?.?!. ?..!. ?.. …!?
!!.?! !!! ?.?!. !!! !!! !!.?. … … …! ?!!.? … …
…? .?!.? … …!. ?.. … …! ?!!.? !!! !!! !!?.? !.?!!
!!! .?.. …! ?!!.? !!! !?.?! .!!! !!!. ?.. … !!!. !!!
??? .?!.? !!! !!! !!! .?.. … … …! ?!!.? … …
… .?.?! .?.. .!.?. … …!? !!.?! !!! !!?.? !.?!! !!! !!.?.
… … …!?! !.?!! !!! !!! ?.?!. !!! !!! !!! !!! !!.?.
… … … .!!! .?.. … … …?. ?!.?. …!. ?.. …
!!!. !!! ??? .?!.? !!! !!!. … …!. ?.. …!? !!.?. …
?.?!. ?.. … …!. … … …! .!!! !!! !!! !!! …
…! .?.. … … …! ?!!.? !!! !!! !!! !?.?! .!!! !!!
!.?.. … … .!!! .?.. … …? .?!.? … … … …
…!.? … … …!? !!.?! !!! !!! !?.?! .!!! !!.!! !!! !!!
!!! … …!.? … … … !!!. ?.. … … ?.?!. ?..
… … …! .?.. …! ?!!.? !!! !?.?! .!!! .!!! !!!.? …
… … !!!. !!! !!! !!! ?.?!. ?!.?. … … … .!!!
.?.. … … …?. ?!.?. … … … … … !.?.

搜了一波發現是Ook!編碼,直接線上網站解碼線上解碼
得到flag

rsa
給了n,c,e,可用線上網站分解線上分解
不行的話首先用yafu分解n。具體方法為

.\yafu-x64.exe “factor(@)” -batchfile 123.txt

得到兩個素數,直接上指令碼

#encoding:utf-8
import gmpy2

p = 2499568793
q =4568695582742345507136251229217400959960856046691733722988345503429689799935696593516299458516865110324638359470761456115925725067558499862591063153473862179550706262380644940013531317571260647226561004191266100720745936563550699000939117068559232225644277283541933064331891245169739139886735615435506152070330233107807124410892978280063993668726927377177983100529270996547002022341628251905780873531481682713820809147098305289391835297208890779643623465917824350382592808578978330348769060448006691307027594085634520759293965723855183484366752511654099121387261343686017189426761536281948007104498017003911
e = 65537
c = 575061710950381118206735073806398116370706587076775765253483131078316908073202143802386128272374323616239083134747318254436706806781744501903333604772961927966747648954315962269321297121495398057938617145017999482722197661065698707836824505023856306403892307944203245563411961302499347604417024064678999003637933185177922884103362203639349298263339808508185861692596967147081382566246627668898774233029198694500565511361867375668367875805985660705137109665107860799277624050210666866958502948062330037309873148963011192405012811945540153592090345668265964477204465327474208098404082920129178960510763496025906621820

n = p * q
fn = (p - 1) * (q - 1)
d = gmpy2.invert(e, fn)
h = hex(gmpy2.powmod(c, d, n))[2:]
if len(h) % 2 == 1:
    h = '0' + h
s = h.decode('hex')
print s

得到flag在這裡插入圖片描述
在這裡發現個好東西rsa套路講解的很詳細,可以看看。
easyrsa

針對e和φ(n)不互素的情形,程式碼指令碼如下


from Crypto.Util.number import *
import sympy
def gcd(a,b):
    if a < b:
        a,b = b,a
    while b != 0:
        tem = a % b
        a = b
        b = tem
    return a
def invalidExponent(p,q,e,c):
    phiN = (p - 1) * (q - 1)
    n = p * q
    GCD = gcd(e, phiN)
    if (GCD == 1):
        return "Public exponent is valid....."
    d = inverse(e//GCD,phiN)
    c = pow(c, d, n)
    plaintext = sympy.root(c, GCD)
    plaintext = long_to_bytes(plaintext)
    return plaintext
def main():
    e = 0x20002
    c = 69775954010477827342655007357413905879265207201140046408669586721885526123784907133716642304622235420317538384169817488136355157658329703705226141938991105912868209447036610553660972001461632840370922684108791263764483626927583087998066070299767122268085587208956687449243493403662943691619787801332549149107
    p = 12470704223521630361963826771946763220892587623191431207923413178791149916874153397100361890510496084700189763294677638398021009427510131598570281465633547
    q = 12470704223521630361963826771946763220892587623191431207923413178791149916874153397100361890510496084700189763294677638398021009427510131598570281465633283
    plaintext = invalidExponent(p,q,e,c)
    print plaintext

雖然搞不清楚為啥,以後慢慢回頭再看(咕咕咕)