• Home
  • About
    • Rhy7hm photo

      Rhy7hm

      天天被计算机教做人

    • Learn More
    • Email
  • Posts
    • All Posts
    • All Tags
  • Projects

基础命令【linux,gdb,python,tmux,git,ssh,c++ ...】

23 Mar 2019

Reading time ~3 minutes

记录的都是一些笔者比较常用的命令……和坑(?)

linux场合

想一直看机子上的共享内存有什么变化,虽然说如果两秒才看一次的话可以用ipcs enter ipcs enter repeat ,但是现在你希望最好可以0.1秒看一次怎么办?

用watch

watch -n 0.1 ipcs

想删除某片共享内存怎么办?

ipcrm -M 0x...

想删除所有owner是xxx的共享内存怎么办?

1.ipcsm查看 + 把 owner是xxx的共享内存的key背下来 + 执行n次ipcrm -M 0x...

2.

set -x       

ipcs -m | awk '$3=="xxx" {print $2}' |
while read s
do
    ipcrm -m $s
done

x64上交叉编译32需要

sudo apt-get install gcc-multilib

想查看文件的某几行怎么办

1.vim filename + (:1,4 delete + enter) + (:11,$ delete + enter),看

2.sed -n '5,10p' filename

批量移动

mv a.dir b.dir c.dir 1.txt 2.txt -t des.dir

gcc选择头文件路径

gcc .c libc.c -I.

动态链接库

export LD_LIBRARY_PATH=.

查看公钥

cat ~/.ssh/id_rsa.pub

下载,另存为

wget -O

解压

tar zxvf FileName.tar.gz

解压到指定的目录

tar -zxvf /home/images.tar.gz -C /specific-dir

unzip: -d

查看系统框架、系统信息

arch

uname -a

更新源

sudo vim /etc/apt/sources.list

1、从服务器上下载文件

scp username@servername:/path/filename /var/www/local_dir(本地目录)

2、上传本地文件到服务器

scp /path/filename username@servername:/path

from xxx import *的xxx是个软链接,python执行报错怎么办?

用python3

pip3死都装不了怎么办:

python3 -m pip

一打开博客发现blog依赖又出bug了怎么办:

sudo bundle update

想看每个进程跑在哪个核上怎么办

ps o pid,psr,comm,cmd

watch + awk 用法 试举例

watch -n 0.1 "ps -aux |awk '{print \$11}' "

甚至可以

watch -n 0.1 "ps -aux |grep lib-store |awk '{print \$11 \$12 \$13 \$14 \$15 \$16 \$17 \$18 \$19}'"

挂起

jobs

bg

fg


tmux场合

为了达到某个奇怪的目的需要同时跑两个进程连用shell写proc1 & proc2然后运行的时间误差都不想有怎么办?

——tmux里的多窗口同步:

set synchronize-panes on

tmux开鼠标:

set -g mouse on


gdb场合

gdb走入一个函数想跳出怎么办

finish

跑crash

gdb-peda$ r < lib-store.crash/crash

下断点:

b *0x401206

b *main+95

set命令

set args 设置命令行参数

set env environmentVarname=value 设置环境变量。

watch命令

watch expr 为表达式expr设置一个观察点,一旦表达式值有变化,马上停住程序 rwatch expr 当表达式expr被读时,停住程序 awatch expr 当表达式的值被读或被写时,停住程序。 info watchpoints 列出所有观察点

查看线程

ps -aux | grep level4

ps -T -p 26548

关于gdb里面的x(念叉(×))

看内存详细情况:xinfo 0xf7fb3059

看命令内存里放的命令:x/5i 0x804861b

看内存里的内容(16进制):x/50x 0xff83d840

看栈:stack 20


git场合

准备工作:

git config --global user.email "你邮箱地址"

git config --global user.name "你的名字"

开始参与项目:

克隆项目

git clone 项目地址

cd 该项目的目录

创建分支

git branch 分支名

转换分支

git checkout 分支名

然后做你想做的修改

改完之后添加修改进暂存区

git add .

其中.是当前目录的意思

提交更改

git commit -m "提交信息"

让远程的知道 git push origin 分支名


附: git status:查看状态

git diff:查看修改

git branch:查看分支

git checkout .: 撤销本地修改(已 add/ commit的不适用)

git log :查看历史记录(commit)

git reset --hard 版本号前几位:撤销、回退


睡一觉醒来继续修改这个项目之前,先取回远程上的更新

git pull origin master

其中master是要取回更新的分支名


怎么使用submodles?

git-submodules

创建项目

git submodule add https://github.com/chaconinc/DbConnector

clone项目

git clone --recurse-submodules https://github.com/chaconinc/MainProject


ssh免密登陆场合

一般使用ssh,都是ssh user@host然后输入密码

当然现在我更常用的是免密登陆

0x00 从零开始:

ssh-keygen -t rsa ssh-copy-id -i ~/.ssh/id_rsa.pub 用户名@ip

0x01 查看(client端)公钥

cat ~/.ssh/id_rsa.pub

0x02 (在sever端)添加公钥

vim ~/.ssh/authorized_keys

把公钥追加上去即可,保存后,拥有该公钥的客户端就有登陆该服务器的权限了。

此时ssh -p 端口 用户名@服务器域名或ip即可登录服务器。

接下来是能让以后登录更方便的设置

###0x03

vim ~/.ssh/config

增加

Host 自取别名

User 同户名

HostName 服务器域名或ip

Port 端口号

IdentityFile ~/.ssh/id_rsa

以后要登陆服务器直接ssh 自取别名即可


其他场合

跨框架编译试举例

arm64编译:

aarch64-linux-gnu-gcc first.c -o first_aarch64

powerpc-linux-gnu-gcc test_source.c -o test_powerpc

运行: qemu-aarch64-static -L /usr/aarch64-linux-gnu/ ./first_aarch64


vim里的替换:

%s/cgc_//gi


查看error

#include <string.h>
#include <errno.h>
printf("errON[%d]errMsg[%s]\n",errno,strerror(errno));

pyc反编译

uncompyle6 servers.pyc > servers.py

C++场合

include

#include <> 和#include ""都会在实现定义的位置查找文件,并将其包含。

区别是若 #include “” 查找成功,则遮蔽 #include <>所能找到的同名文件;否则再按照 #include <> 的方式查找文件。

一般来说 #include <>的查找位置是标准库头文件所在目录,#include ""的查找位置是当前源文件所在目录。不过这些都可由编译器调用参数等配置更改。


【C/C++】全局变量只能初始化不能赋值

c语言编译器默认以main作为入口地址,当然改变的方法也有很多,如使用__attribute__等

所以我也不知道我这段代码是想干嘛

  1 #include <stdio.h>
  2 #include "head.h"
  3 int a ;
  4 a = 233;
  5 tesshead();
  6 int main()
  7 {   
  8     tesshead();
  9     int a = 3;
 10     int b = 4;
 11     swap(a,b);
 12     return 0;
 13 
 14 }

反正4、5行都会报错:

error: C++ requires a type specifier for all declarations

命名空间和类和构造函数

命名空间不可怕……

在一个命名空间里调用另一个命名空间里的函数或类

直接space_name::function_name

或

space_name::class_name都是没问题的

要使用这个类里面的函数

就先space_name::class_name abc

再abc.function_name()

问题在于,我之前怼的Fuzzer类的构造函数是带参数的

所以直接fuzzer::Fuzzer abcd新建会爆一个

error: no matching function for call to ‘fuzzer::Fuzzer::Fuzzer()’

python场合


url编码、译码

from urllib import urlencode

from urllib import unquote

python中文

# -*- coding: utf-8 -*-

反序:ss=s[::-1]

字母+数字

table = string.lowercase + string.uppercase + string.digits

开文件

with open('/path/to/file', 'rb') as f:
    infoq=f.read()

字符串异或:

c=''.join(chr(ord(a) ^ ord(b)) for a,b in zip(infoq,infop))

分块 [s[i:i+2] for i in range(0,len(s),2)]

def chunk(input_data, size):
	return [input_data[i:i+size] for i in range(0, len(input_data), size)]

[a[i:i+size] for i in range(0, len(a), size)]

map(lambda x:s[2*x:2*x+2],range(len(s)/2))

全排序(遍历所有情况)

import itertools

不重复: combinations(items, 3)

会重复: combinations_with_replacement(items, 3)

字典按values排序:

rs =[(key,value) for key, value in sorted(dist.iteritems(), key=lambda (k,v): (v,k),reverse = True)]

字符串与十六进制

char2hex:output = 'data'.encode('hex')

hex2char: output = '64617461'.decode('hex')

md5:

import hashlib

d=hashlib.md5(data).hexdigest()

DES

cipher = AES.new(key, AES.MODE_ECB)

msg = cipher.decrypt(miwen)

>>>li = ['my','name','is','bob'] 
>>>' '.join(li) 
'my name is bob' 

>>> b = 'my..name..is..bob' 
 
>>> b.split() 
['my..name..is..bob'] 
 
>>> b.split("..") 
['my', 'name', 'is', 'bob'] 

删去末尾指定的字符

str.rstrip([chars])

大小写字母+数字

table = string.lowercase + string.uppercase + string.digits

字符串转二进制

ss=''.join([bin(ord(c)).replace('0b', '').rjust(8,'0') for c in s])

B64

>>> import base64
>>> s = '我是字符串'
>>> a = base64.b64encode(s)
>>> print a
ztLKx9fWt/u0rg==
>>> print base64.b64decode(a)
我是字符串

到十进制:

int('0xf',16) 
int('17',8)    
int('10100111110',2)      

到十六进制:(先转到10进制再hex)

hex(1033)
hex(int('17',8))
hex(int('101010',2))

到二进制: bin(10) ↑十进制转二进制

 bin(int('ff',16))
 bin(int('17',8))

命令行

os.system(command)

要获取返回:

os.popen('ls').read()

隐藏: $ steghide embed -ef intelligence.txt -cf lena.jpg -sf output.jpg 提取: $ steghide extract -sf output.jpg


参考

https://www.google.com

https://blog.csdn.net

https://www.zhihu.com



Linuxgdbpython Share Tweet +1