TTY 小實驗

2019-08-18
  • a.c

    #include <unistd.h>
    #include <stdio.h>
    
    int main() {
        printf("istty(%d) = %d\n", 0, isatty(0));
        printf("istty(%d) = %d\n", 1, isatty(1));
        printf("istty(%d) = %d\n", 2, isatty(2));
    }
    
  • a.out

    gcc a.c
    
  • tests

$ ./a.out
istty(0) = 1
istty(1) = 1
istty(2) = 1

$ ./a.out | cat
istty(0) = 1
istty(1) = 0
istty(2) = 1

$ ./a.out 2>&1 | cat
istty(0) = 1
istty(1) = 0
istty(2) = 0

$ ./a.out 2>&0 | cat
istty(0) = 1
istty(1) = 0
istty(2) = 1

$ cat | ./a.out
istty(0) = 0
istty(1) = 1
istty(2) = 1

Reverse shell 重設 tty 尺寸

在你 local terminal 看尺寸

stty -a

在 reverse shell 打

stty rows 30 columns 110 # 看你 terminal 多大