CheatSheet

不可视境界线最后变动于:2023年8月25日 上午

Kali&Linux的问题

linux命令在这

  • 虚拟机的安装(又装了一遍)
  • VMtools的安装(为什么网上会有这么多的方法.
  • 中文输入法Ibus的安装(两行命令解决的事情有些教程搞得几十行,就离谱)
  • vim插件(彻底的失败) 不过在vim设置文件里设置了几个常用的.
  • 密码问题, root初始密码忘记, root下passwd指令. 默认账号kali kali
  • vim在share文件夹里
  • 中文输入法出现[Invalid-UTF-8 code], 改成半角中文即可
  • make btest出错, 修改Makefile为生成64位可执行文件[0].
  • LInux中可执行文件和后缀名无关, 和文件的属性有关(????
  • bitset是一个类模板
  • GDB以及gcc的使用(详见零碎知识)
  • kali如何运行可执行文件: ./bomb
  • 中文输入法下输入命令:w按下回车vim会卡死, 输入逗号也能卡死?????
  • kali装Chrome:他有sandbox机制, 无法在root用户下运行[1].
  • kali使用vpn: 失败.
  • kill占了端口的进程[0].
  • 虚拟机卡死时查找log文件里的pid, 在任务管理器里停止
  • 查看磁盘使用情况[0].
  • Typora的安装问题.
  • .tar文件相关问题.
  • root用户安装了vmtool, 切换到lbjyye后需要重新安装(?)
  • 修改命令行终端字体大小: ~/.config/qterminal.org/qterminal.ini 里的fontsize或fontfamily并将其改为只读文件(新版完全没这个问题)
  • 要显示隐藏文件夹直接到工具栏上的视图里去找
  • 延长锁屏时间
  • chorme里添加搜索引擎
  • vim无法打开文件, 改为下载GVIM
  • 啥玩意儿啊, kali2021干吗搞没了图形界面clash弄半天也没成[0]
  • main函数的两个参数: 一个是命令参数的个数, 另一个是命令参数数组,argv[0]是程序本身的文件名
  • **Typora里使用中文状态下的Ctrl+A, 文件直接丢失!!!!**太特么蠢了.
  • /usr/share/vim/vim82/colors/有vim的主题
    • industry 全黑, evening 还行, koel 超级黑的背景, morning 灰白很不错, murpy又是黑的字体细点, peachpuff 桃色背景, shine 亮瞎狗眼 颜色太浅, slate 字体太紧, zellner 平平无奇的白底, 剩下的不用考虑
  • 了解了链接引用和脚注是个.
  • Operation inconsistent with current state。VM报错, 只要以管理员身份运行就可以了
  • Linux中的Chrome无法自动升级,干脆就不升级了, 命令加一个--disable-background-networking
  • kali中使用中文输入法的时候无法在vscode中用光标选中文本
  • Kali成功登上google, 使用chrome的代理就成. 算是搞明白一点代理是怎么回事了, Kali没有全局代理只能再需要的软件里面设置代理, 命令行程序要用代理要装proxytrain
    • proxychains使用方法, 其中本机ip地址为无线局域网适配器 WLAN: ipv4那一栏的地址
    • 终于啊, kali和ubuntu都能走代理了:sob:
    • 过了一天好像又不行了, 换成127.0.0.1 7891后换了个新版本才行. link
  • 非正常关机后要启动虚拟机只要删除 .lck磁盘锁文件夹即可.
  • 把kali的zsh设置(功能真的是相当全)直接弄到pwn.college上面, 整个界面就好看多了.
  • bash_wildcard!
  • start with cli in Kali :
    systemctl set-default multi-user.target start display-manager.service set-default graphical.target
  • 像seccomp ltrace的路径必须是相对路径, 如果只写个文件名是不行的.
  • shell scriping tutorial
  • 为了shelltools又装了一个apt install gcc-i686-linux-gnu, 不知道有没用.
  • zsh_hist:
1
2
3
4
5
6
7
8
%s/^\s*\d\+.\=\s\+//g 	#trim `history -i 0` lineno in vim
history -i -n 0 #print all history in timeformat
awk 'match($0,/: ([[:digit:]]+):/, a) {if(a[1]>1658275200) print $0;}' .zsh_history > /mnt/hgfs/LearingList/configFile/zsh_hist_new #add new history
awk 'match($0,/: ([[:digit:]]+):/, a) {if(a[1]>$1) print $0;}' .zsh_history > /mnt/LearingList/configFile/zsh_hist/$(date +"%y%m%d") #in script
#remove duplicate
cat .zsh_history | sort -k2.14 -u | sort -k2 > .zsh_history.tmp
#or in one line.
cd;sort -k2.14 -u .zsh_history | sort -k2 > .zsh_history.tmp;mv .zsh_history.tmp .zsh_history;cd $OLDPWD
  • 使用ssh pubkey连接到虚拟机中时遇到问题, 总是显示permission denied, 搜了两三个小时无果后终于发现在kali里面查看auth日志tail -f /var/log/auth.log可以看到是/root文件夹的grouping write权限导致ssh server拒绝连接. 直接一个chmod 700 /root解决问题.

  • vscode可以使用move terminal to editor area命令, 含义就是字面意思.

  • 没想到mnt文件夹下我没有修改权限, 怕是vmware认定成共享文件夹专用地, 导致其他文件不能mount到/mnt下面. 又新建了一个/_mnt用着. 感觉大部分脚本都会用到/mnt文件夹. 诶算了用到了再说吧.

vim进阶

  • 自动提示: <C-n><C-p>
  • vim路径补全
  • vim添加tab切换快捷键, 以及单界面多文件操作.
    1
    2
    :map ^[OR :tabp<CR>
    :map ^[OS :tabn<CR>
  • 折叠: zM: close all zr: open all za: openOrClose zA: sameButRecursively
  • 颜色option
  • autocmd BufNewFile,BufRead gdb* set filetype=gdb 设置默认的语法高亮.
  • vim range and this
  • vim先输入数字然后进入插入模式后输入几个字符, 再返回普通模式会重复输入
  • :e => reload file
  • vim plug list -> link | 装上了tabcompletion. + python completion
  • gt gT nnngt: switch tabs.
  • Ctrl-O: enter insert select mode, can exec one command then.
  • motions(many details) |
  • ; : Repeat latest f, t, F or T [count] times.
  • echo &var will print out the variable value.
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    "dl"    delete character (alias: "x")           dl
    "diw" delete inner word diw
    "daw" delete a word daw
    "diW" delete inner WORD (see WORD) diW
    "daW" delete a WORD (see WORD) daW
    "dgn" delete the next search pattern match dgn
    "dd" delete one line dd
    "dis" delete inner sentence dis
    "das" delete a sentence das
    "dib" delete inner '(' ')' block dib
    "dab" delete a '(' ')' block dab
    "dip" delete inner paragraph dip
    "dap" delete a paragraph dap
    "diB" delete inner '{' '}' block diB
    "daB" delete a '{' '}' block daB
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    gUU  : Make current line uppercase.
    guu : lowercase.
    gU{motion} and gu{motion} Make {motion} text uppercase.

    {Visual}CTRL-A # INC
    {Visual}g CTRL-A # sequencial add
    set nrformats=bin,hex # this is default. can include `octal` `alpha`
    Use the following

    steps to make a numbered list.
    1. Create the first list_entry, make sure it starts with a number.
    2. qa - start recording into register 'a'
    3. Y - yank the entry
    4. p - put a copy of the entry below the first one
    5. CTRL-A - increment the number
    6. q - stop recording
    7. <count>@a - repeat the yank, put and increment <count> times
  • complex changes : toooooo complex.
  • regex pattern | and an useful post
  • qa记录到a中, @a执行宏, num@a执行num次, @@执行上一个宏.
  • variable motion, 比如说跳到下一个method或者#if.

tmux+gdb

  • tmux tmux-voltron tmuxinator voltron 这方法可能没啥用.
  • 使用pwndbg的split: features | split mind
  • tmux config | cheat sheet | tutorial
  • 加载config文件失败: tmux kill-server or reload
  • for i in {0..255}; do printf "\x1b[38;5;${i}mcolor%-5i\x1b[0m" $i ; if ! (( ($i + 1 ) % 8 )); then echo ; fi ; done找到所有的颜色.
  • <prefix> !或者:join-pane -t <int>可以将一个spane移进或移出.
  • Ctrl+b, ., 222 (renumber) | Ctrl+A+q = windows number |
  • <C-a>} (:swap-pane -R) – move current pane to the right side
  • <C-a><Space> – toggle pane arrangements
  • <C-a>{ (:swap-pane -L) – move current pane to the left side

ubuntu2004

  • ubuntu虽然任务栏不好用, 但是有快捷键挺舒服的, 继续记!
  • ubuntu sudo命令延时很长解决办法
  • 更新ubuntu源
  • linux终端快捷键
  • 通过增加快捷键绑定解决vim终端中无法使用方向键的问题
  • init 0重启发现挂载失败了, 之前那个命令也不管用了, 只能倒回上一个快照继续, 还好博客都是用的共享文件夹.
    不说了, 快照再次救我一命.
    • 找到了解决办法, 要给普通用户权限访问
1
echo " " | sudo -S vmhgfs-fuse -o allow_other ......
  • colorizing man pages: link && zsh

  • save zsh history and multiterminal-hisory-share link

  • zsh-autosuggestions: kali默认装上而ubuntu没有的(他有个啥??)自动历史命令建议.
    使用sudo apt install zsh-autosuggestions即可装上.

  • 通过修改/etc/passwd文件来使得root用户的home换到/home/lbjyye, 先尝试一段时间, 真的不想打sudo, kali root用习惯了

    1
    2
    chmod -R 755 /home/lbjyye/.local/share/zinit
    chown -R root:root /home/lbjyye/.local/share/zinit
  • docker-desktop的旧context整的我半天用不了……

  • 发现代理失效了, 试了半天结果删除了设置中的FTP代理地址就成功了. 不然之前连google都上不去. 玄学问题, 既然解决了就不管了.

ubuntu2204

各种命令+软件包

  • ldd strace(刚刚装的) head打印前n行 du显示文件大小 ps打印进程信息
    • ldd: print shared object dependencies
    • ps aux – BSD参数风格
  • Linux下!用法, 主要是传递最后执行的命令的参数,以方便的运行新命令(非常实用)
  • ln命令|symbolic_link
  • scp & mkdir & mv(linux中重命名的唯一方法)
  • screen: window manager, 好多快捷键, 复制了一份.screenrc, 还挺有趣的.
    • screen这玩意儿也太强了.Ctrl + A + [进入copy模式才能使用滚轮或者Ctrl+F/B等等来翻页(已经改成<C-/>)
  • 看到一个cscope包可以用来解析C/C++项目, 有空再研究怎么玩(谁玩啊2
  • vim-gtk是vim的一个GUI版本, 装了之后才能vim -g
  • 新命令: tput好像是用一个通用命令做参数, 然后在当前终端的数据库中找到正确的命令并发送
  • ipython: System shell with ! interactive Python也挺神奇的, 具体见pwn-modules里的帮助.
  • 发现grep有拓展正则和普通正则的区别, 又是一大堆东西, 有缘再看吧.
  • 新东西: sed, stream editor. 还有一个ed, 根本不知道怎么用. 这东西这两天把菜鸟教程上所有的命令全看一边就行了 上面没有.
    rev nl perror
    • 真不错, 用了sed来改c.c中的题目标号, 再方便一点.
  • find的功能真的很多, 又是一个相当强大的工具. e.g. find . -name Makefile
  • wc 命令, 计数文件字节数 行数等等.
  • uniq report repeated lines.
  • ls -ARl * 递归展示文件并且不显示.和.. 还能显示符号链接 以及tree命令
  • shuf generate random permutation.
  • sleep infinity 手册里完全没看见这个infinity, 不过作用也显而易见了.
  • xargs build and exec commands from standard input.
  • bat cat(1) clone with syntax highlighting and git integration.
  • awk IBM doc
  • sort : -k 可以指定跳过前面几个字符.
    1
    2
    3
    KEYDEF is F[.C][OPTS][,F[.C][OPTS]] for start and stop position, where F is a field number and C
    a character position in the field; both are origin 1, and the stop position defaults to the
    line's end.
  • du -sh show directory contents size.
  • cut : cut -d' ' -f1 /proc/uptime 等同于 awk '{print $1;}' /proc/uptime
  • xz + tar
    • compress to limit:tar -cf - SalesData | xz -9ze -T0 >SalesData.tar.xz
      or cheaper: tar cfJ output.tar.xz inputfiles
    • decompress:tar xf archive.tar.xz

Docker

  • How to exit the running container? here : that is pressing ctrl+p && ctrl+q.
  • sudo docker exec -it CONTAINER_ID sh exec: run command in a running container.
  • docker rm/rmi docker ps -all docker images
  • docker file reference | docker compose reference
  • netstat -antu to check whether some container is using ports or not.
  • remove used data: prune
  • docker run
  • service docker restart
  • docker-compose
    • up = start container, down = remove container
    • only after removing container can it rm image. maybe dc container prune
    • dcc up -d + dcc exec [service name] bash: setup a interactive shell
  • docker commit: 可以commit已修改的container.
  • 绑定单个文件: --mount type=bind,source="$(pwd)"/file.txt,target=/file.txt,readonly
  • 更换apt和pip源:
1
2
3
RUN sed -i "s@http://\(deb\|security\).debian.org@https://mirrors.aliyun.com@g" /etc/apt/sources.list
RUN mkdir /root/.pip
RUN echo "[global]\nindex-url = https://pypi.tuna.tsinghua.edu.cn/simple" > ~/.pip/pip.conf
  • docker desktop: BIG FAILURE, gnome desktop environment | KVM in kali is not supported | ubuntu 22.04 wired problem | kali root account cant open docker desktop | kali normal account cant open settings. there are so many problems.
  • docker engine: building and containerizing your application
  • docker compose: defining and running multi-container Docker applications.
    • in one container’s circumstance, the same as docker engine.
    • compose file’s format
  • expose or publish
    • EXPOSE is a way of documenting
    • --publish (or -p) is a way of mapping a host port to a running container port

Shell

zsh

  • expansion

    • history exp

    • !ls:$:a:获取上一条以 ls 开头的命令的最后一个参数,并将其转换为完整路径。
      冒号是用来分割Word Designators和event和Modifiers

    • Process Substitution <(list), >(list) or =(list) 都是进程补全, 用于将一个进程的输入或输出重定向到文件句柄中

    • Parameter Expansion 还有Expansion Flags可用(真的多)

      • ${name+word} ${name:+word}: 如果name设置为非空,或者第二种形式为非空,则用word代替; 否则用NULL代替

      • ${(@)${foo}[1]}: 更安全的数组索引, 在元素中含有空格的时候也能准确取出整个元素.

      • ${(@)foo}: 形式为’[*]’或’[@]’的下标求值为数组的所有元素. 在parameters/array/array subscripts中.

      • $#para: 指代para的长度. 如果POSIX_IDENTIFIERS已设置则和bash一样, $#仅指代位置参数长度. 在shell emulation中.
        可用${#para}`来区分. - - command exp: `$(...)` - Arithmetic exp: `$[exp]` or `$((exp))` - brace exp: `foo{xx,yy,zz}bar` fooxxbar fooyybar `{n1..n2..n3}` - filename exp: `hash -d work=/Users/binjie09/Work` - Filename Gen: - glob ops: `x##` `x#` `x~y` - glob flags: 用在`#`的后面, 用括号围起来: `ls (#i)*.txt` 1. `(#i)`:开启不区分大小写的匹配模式。 2. `(#m)`:`${arr//(#m)[aeiou]/${(U)MATCH}} //全局匹配 (U)大写

        1. (#cN):设置最多匹配 N 个文件
        2. (#b): 数组下标从1开始.
        1
        2
        3
        foo="a_string_with_a_message"
        if [[ $foo = (a|an)_(#b)(*) ]]; then
        print ${foo[$mbegin[1],$mend[1]]}; fi
      • approximate match: (#anum) 不同字符 不同顺序 多了 少了 四种情况的匹配. 用作前置flag, num指代数量.

      • Recursive Globbing: ls **/bar ls **.c=ls **/*.c

      • Glob Qualifiers: 在最后面一对括号中的flag. 对文件的类型进行限制, 甚至执行代码

  • built-in commands

    • read
    • whence: whence -ca = where
      对于每个名称,说明如果将其用作命令名将如何解释。-f:alias, builtin, command, function, hashed, reserved or none
    • zcompile: 预编译

Shell programming

好多东西, 看了下感觉更会用shell了. 注意, 我倾向于使用zsh, 但有部分bash内容 bash小抄

  • printf使用示例:

    • printf '%d %d %d %d' \'a 3 4 \'a printf "\\$(printf %o 74)" printf "\\x$(printf %x 65)"
  • double-parenthesis | '$1 : leading-quote | condition expr(bash doc P98) |

  • seq 生成序列.

  • dup2可用来实现shell的redirection. 还可以指定fd. 好像之前的一题又有新的解决方法了, 不过得用c来写.

  • 开启了extglob(zsh) | extglob(bash)之后, 可以使用?*+@!(pattern-list)这五种.
    zsh还可以用^等等, 文档在这儿.
    知道这些之后就可以更好的filter file了

    • rm -r ^(sh|1_sh)
    • ll ^(|*sh) 两个都加只能这样.
  • cp --preserve=links 或者 cp -av就可以复制symlink了.
    v只是verbose的意思, a覆盖了一些选项, 用于完整的复制文件本身.

  • while [ 1 ]add spaces between 1.

  • 判断子串:

    • ${string##*cd*} 这个##会从string删除匹配字符串就挺神奇的. 得用[ -z ... ]来判断成功.
  • cd’s special function in zsh:

1
2
3
cd [ -qsLP ] [ arg ]   #change to arg
cd [ -qsLP ] old new #替换path中的字符串
cd [ -qsLP ] {+|-}n #打开dirs输出的entry, +-表示顺序
  • print:
1
2
print [ -abcDilmnNoOpPrsSz ] [ -u n ] [ -f format ] [ -C cols ]
[ -v name ] [ -xX tabstop ] [ -R [ -en ]] [ arg ... ]
  • declare 用于查看已声明符号的信息
  • read命令的prompt尝试全部失败…但是在命令行中是可以的.
  • 注意单双引号的区别, 单引号原样打印.

Deamon

  • pronounciation: /ˈdiːmən/
  • the parent process is often, but not always, the init process. often ends with d letter.
  • deamon exp.: crond | xinetd |

Coding in windows

mount+pwntools

在windows下使用共享文件夹+装上pwntools+ssh连接kali = 主机写代码, 带有补全高亮, ssh输入命令.

Vscode ssh

暂时还是不用了, 这个和虚拟机里的vscode插件并不一样. 装两次属实没必要. code server已经装上了, 也不知道哪里卸载.

已真香.

Architecture diagram

pwntools

rop

dump(base) chain(base) elfs gadgets migrated: 显而易见
base: 只是为了dump好看点
pivots: 能把stack指针移动多少字节的地址. dict
resolve(str|int): str就解析, int就直接返回.
unresolve(int): 逆过程
generatePadding(offset, pad): 生成pad, 不加入rop chain中. bytes

search_iter(move=20, regs=[‘rdi’, ‘rsi’]): 返回的是generator, 在迭代中使用的东西
search(move=0, regs=None, order=’size’): 显而易见
find_gadget([‘pop rdi’, ‘ret’]): 显而易见
setRegisters({‘rdi’:0xbeef}): 找到gadgets来设置相应寄存器

raw(): dddd
ret2csu(): 废物一个, 不用了.
ret2dlresolve(): 额,
call(resolvable, arguments=()): 显而易见
migrate(next_base): 简单粗暴pop rbp.
rop.rdirsirdxrcxrbx…leave…ret…: 以上都是直接设置rop链的.

build(): 输出list, 能够flat()

IOT

  • docker run --rm -v $PWD:/firmware cincan/binwalk -Mer "/firmware/firmware.bin"
  • ssh -oHostKeyAlgorithms=+ssh-rsa root@192.168.110.101 or 在.ssh/config下添加两行
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
	(ssh:)
ifconfig eth0 192.168.2.2/24
tar czf 1.tar squashfs-root/
scp 1.tar root@192.168.10.2:/root/
ssh root@192.168.110.101
tar zxvf 1.tar
mount -o bind /dev ./squashfs-root/dev
mount -t proc /proc ./squashfs-root/proc/
chroot ./squashfs-root/ sh
/usr/sbin/uhttpd

ifconfig eth0 192.168.2.2/24
mount -o bind /dev ./squashfs-root/dev
mount -t proc /proc ./squashfs-root/proc/
chroot ./squashfs-root/ sh
/usr/sbin/uhttpd
  • qemu_start.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#!/bin/sh 
qemu-system-mips \
-M malta \
-kernel vmlinux-2.6.32-5-4kc-malta \
-hda debian_squeeze_mips_standard.qcow2 \
-append "root=/dev/sda1 console=tty0" \
-net nic -net tap,ifname=tap0,script=no,downscript=no \
-nographic

#!/bin/bash
qemu-system-arm \
-M vexpress-a9 \
-kernel ~/tools/IOT/kernel_disk/armhf/vmlinuz-3.2.0-4-vexpress\
-initrd ~/tools/IOT/kernel_disk/armhf/initrd.img-3.2.0-4-vexpress \
-drive if=sd,file=/root/tools/IOT/kernel_disk/armhf/debian_wheezy_armhf_standard.qcow2 \
-append "root=/dev/mmcblk0p2" \
-net nic -net tap,ifname=tap0,script=no,downscript=no \
-nographic \
-audiodev none,id=snd0
1
2
3
4
5
6
7
8
9
#docker git/wget proxy
export http_proxy="http://127.0.0.1:7890"
export HTTP_PROXY="http://127.0.0.1:7890"
export https_proxy="http://127.0.0.1:7890"
export HTTPS_PROXY="http://127.0.0.1:7890"

#make /dev/null
mknod /dev/null c 1 3
chmod 666 /dev/null

开启telnet: http://127.0.0.1/goform/telnet, telnet admin/password is root/Fireitup.

env

  • jefferson
  • lzop
  • Firmware
  • burpsuit
  • default-jre
  • docker pull capysix/firmae-orig-test:5.13c
  • apt install libelf-dev:i386
  • am-toolchains
  • gdb-multiarch

netgear

  • cve-2019-5054: docker环境下poc无效果 完成
  • cve-2019-5055: 环境搭建未成功, hostapd启动方法暂时未知
  • (new)cve-2023-27852: 无poc 环境也搭不起来,qemu-system显示内核太旧,新版暂时不知怎么找,qemu-static下没有run文件夹.
  • (new)cve-2023-33533: 命令注入poc无效果

Linksys:

  • (new)cve-2023-31742: 命令注入poc无效果, 无法找到apply.cgi文件
  • cve-2019-14333: AP设备, 环境搭建方法暂时未知

Tenda:

  • CVE-2023-26806: W20E 搭建失败 W15E可能也是一样的问题, cfm函数错误, 然后又无法打开窗口
    已解决, 同环境poc修改成功.

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    #compile shared lib(hook GetValue found in old_main_init)
    LD_LIBRARY_PATH=/root/tools/IOT/am-toolchains/brcm-arm-sdk/hndtools-arm-linux-2.6.36-uclibc-4.5.3/lib
    apt install libelf-dev:i386
    ln -s /root/tools/IOT/am-toolchains/brcm-arm-sdk/hndtools-arm-linux-2.6.36-uclibc-4.5.3/bin/arm-uclibc-gcc /bin/ugcc
    ugcc -shared -fPIC -Wall getvalue.c -o getvalue.so

    #gdb
    apt install gdb-multiarch
    set solib-search-path /root/tools/IOT/am-toolchains/brcm-arm-sdk/hndtools-arm-linux-2.6.36-uclibc-4.5.3/lib:/root/TalentSec/Tenda/CVE-2023-26806/hook/

    #patched
    #ucloud_p_sem(跳过信号量) / authSecurityHandler(跳过密码验证)