Linux

[Linux] nmap常用指令

  • 掃描是否alive
nmap -sP target_ip_range
  • 掃描開啟的port以及軟體版本
nmap -sV target_ip
  • 掃描作業系統版本
nmap -O target_ip
  • 使用NSE預設腳本
nmap -sC target_ip

[Linux] ~/.vimrc

set clipboard=unnamed    "connect system clipboard
set ai                   "auto indent
set cindent shiftwidth=4 "C { indent
set nu                   "line number
set tabstop=4            "tab width

[Linux] Vim Clipboard

在Ubuntu中,如果要讓system clipboard和vim的複製指令(dd, yy, 選取後d, y等等…)共通,必續先進行以下步驟:

1.安裝 vim-gui-common

sudo apt-get install vim-gui-common

是否安裝成功,可以在vim中打:set showcmd後,按”+”並查看是否有顯示此指令。

2.更改~/.vimrc設定檔

在~/.vimrc中新增一條:

set clipboard=unnamed

[Linux] .tmux.conf

# 256 colors please
set -g default-terminal "screen-256color"

# Bad Wolf
set -g status-fg white
set -g status-bg colour234
set -g window-status-activity-attr bold
set -g pane-border-fg colour245
set -g pane-active-border-fg colour39
set -g message-fg colour16
set -g message-bg colour221
set -g message-attr bold

# Custom status bar
# Powerline symbols: ⮂ ⮃ ⮀ ⮁ ⭤
set -g status-left-length 32
set -g status-right-length 150
set -g status-interval 5

# Inconsolata-dz-Powerline Theme:
#[fg=white,bg=colour39,noreverse,bold]
#green hostname: fg=colour22,bg=colour148
set -g status-left '#[fg=colour235,bg=colour252,bold] ❐ #S #[fg=colour252,bg=colour238,nobold]⮀#[fg=colour245,bg=colour238,bold] #(whoami) #[fg=colour238,bg=colour234,nobold]⮀'
set -g status-right '#[fg=colour238,bg=colour234,nobold]⮂#[fg=colour245,bg=colour238] #h #[fg=colour252]⮂#[fg=colour235,bg=colour252,bold] #(wemux status_users) '
set -g window-status-format "#[fg=white,bg=colour234] #I #W "
set -g window-status-current-format "#[fg=colour234,bg=colour39]⮀#[fg=colour25,bg=colour39,noreverse,bold] #I ⮁ #W #[fg=colour39,bg=colour234,nobold]⮀"
# Alternate Theme for shells without Inconsolata-dz-Powerline:
# set -g status-left ' #[bold]❐ #S#[default] ⣿'
# set -g status-right '#[bold]#(whoami) ● #H#[default] ⡇ #[fg=blue]%H:%M#[default] '

# Activity
setw -g monitor-activity on
set -g visual-activity on

# renumber windows sequentially after closing any of them
set -g renumber-windows on

# fixes the delay problem
set -sg escape-time 0

# make mouse happy in tmux
# source: https://github.com/tmux/tmux/issues/145
set-option -g -q mouse on
bind -n WheelUpPane if-shell -F -t = "#{mouse_any_flag}" "send-keys -M" "if -Ft= '#{pane_in_mode}' 'send-keys -M' 'select-pane -t=; copy-mode -e; send-keys -M'"
bind -n WheelDownPane select-pane -t= \; send-keys -M

# --------------- LAYOUT

# -v = split horizontal
# -h = split veritical

# CHH dotfiles
bind-key -n M-u new-window -n dotfiles -c $HOME/.dotfiles \; \
 send-keys 'clear && toilet --font bigmono12 "CHHDF" -F metal' 'Enter' \; \
 # split-window -h -p 70 -t 1 \; \
 # send-keys ""

[Linux] Tmux快捷鍵

*以下指令皆須使用前綴(預設Ctrl+b)

pane

% 水平分割出一個 pane
垂直分割出一個 pane
方向鍵 移動到另外一個 pane
x 關閉目前的 pane
space 切換佈局
{ 向前置換
} 向後置換
alt+方向鍵 調整大小

window

c 創建新的 window
& 關閉目前的 window
p 切換到上一個 window
n 切換倒下一個 window
數字鍵 切換到指定 window
, 重新命名 window
. 修改 window 編號

session

$ tmux 開啟一個新的 session
$ tmux ls 列出所有 session
$ tmux a -t 0 進入第 0 個 session
$ tmux kill-session 0 關閉 0 號 session
d 脫離目前 session
s 切換 session

[Mac] 快捷鍵

Terminal:

Control + L: 清空畫面,等同 Clear (或 Command + K)
Control + A: 游標移到最前面
Control + E: 游標移到最後面
Option + Click: 游標移到滑鼠點的地方

通用熱鍵:

Command + Q:關閉程式(Q=Quit=終止、結束)
Command + W:關閉視窗(W=Window=視窗)
Command + O:開啟(O=Open=打開,等於 Windows 系統中按 Enter 開啟的動作)
Command + H:隱藏程式(H=Hide=隱藏)
Command + M:使視窗最小化(M=Minimize=使縮到最小)
Command + N:開新視窗(N=New=新的)
Command + I:顯示資訊(I=Information=資訊)

Finder 相關:

Command + E:退出外接裝置,如隨身碟、光碟(E=Eject=退出、彈出)

瀏覽器相關:

Command + T:開新分頁(T=Tab=分頁)
Command + L:移至網址列(L=URL=網址)
Command+R:重新整理(R=Refresh=刷新)
Command + F:在頁面尋找(F=Find=尋找)

Apple Mail 或 iWork 等文書處理相關:

Command + A:選擇全部(A=All=全部)
Command + S:存檔(S=Save=存檔)
Command + C:複製(C=Copy=複製)
Command + B:加粗體(B=Bold=粗體)
Command + U:加底線(U=Underline=底線)
Command + K:加超連結(K=Hyperlink=超連結)
Command + P:列印(P=Print=列印)

 

[Linux] Makefile相關

1、「=」

make會將整個makefile展開後,再決定變量的值。

x = foo
y = $(x) bar
x = xyz

y = xyz bar

2、「:=」

「:=」表示變量的值決定於它在makefile中的位置。

x := foo
y := $(x) bar
x := xyz

y = foo bar

3、「+=」添加後面的值

4、「?=」變數為空值才指定為後面的值

Kernel Makefile Example:

CONFIG_MODULE_SIG = n
obj-m += simple.o
all:
   make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules
clean: 
   make -C /lib/modules/$(shell uname -r)/build M=$(PWD) clean

[Linux] 核心模組相關

  • 查看當前核心模組
lsmod
  • 安裝模組/卸載模組
sudo insmod modulename.ko
sudo rmmod modulename
  • Kernel List
#include<linux/list.h>
#include<linux/types.h>
#include<linux/slab.h>

struct birthday
{
 int day;
 int month;
 int year;
 struct list_head list;
};

//init list
static LIST_HEAD(birthday_list);

//add element
struct birthday *person;

person = kmalloc(sizeof(*person),GFP_KERNEL);
person->day = 18;
person->month = 10;
person->year = 1996;

INIT_LIST_HEAD(&person->list);
list_add_tail(&person->list,&birthday_list);

//traverse
struct birthday *ptr;
list_for_each_entry(ptr, &birthday_list, list){
 printk("Birth: %d/%d/%d\n", ptr->year, ptr->month, ptr->day);
}

//delete
struct birthday *ptr, *next;
list_for_each_entry_safe(ptr, next, &birthday_list, list){
 printk("Delete element %d\n",i);
 i++;
 list_del(&ptr->list);
 kfree(ptr);
}
  • Kernel Module Sample Code
#include <linux/init.h>
#include <linux/kernel.h>
#include <linux/module.h>
/* This function is called when the module is loaded. */
int simple_init(void)
{
    printk(KERN INFO "Loading Module\n");
    return 0;
}
/* This function is called when the module is removed. */
void simple_exit(void)
{
    printk(KERN INFO "Removing Module\n");
}
/* Macros for registering module entry and exit points. */
module_init(simple_init);
module_exit(simple_exit);
MODULE_LICENSE("GPL");
MODULE_DESCRIPTION("Simple Module");
MODULE_AUTHOR("Hubert");

[Linux] 系統版本相關

  • 查看核心資訊
uname [-asrmpi]
選項與參數:
-a  :所有系統相關的資訊
-s  :系統核心名稱
-r  :核心的版本
-m  :本系統的硬體名稱
-p  :CPU 的類型
-i  :硬體的平台
  • 查看硬體資訊
lshw