Sunday, August 31, 2008

putty+screen + irssi 声音提醒

對於會把 putty 視窗切到背景的人來說,大概會很希望當關鍵字(例如自己的 ID
)出現時,視窗就會發出聲音。

以下讓妳實現這個功能:
在 irssi 裡下達這些指令,讓 irssi 適時發出聲音訊號:
/set beep_when_window_active ON
/set beep_when_away ON
/set beep_msg_level MSGS NOTICES DCC DCCMSGS HILIGHT
/set bell_beeps ON
在 screen 中按以下的按鍵,讓 screen 把 irssi 發出來的聲音訊號傳出來:
<Ctrl>-<l> <Ctrl>-<g>
在 PuTTY 裡做以下設定,讓 PuTTY 接收到聲音訊號時,就播放妳所指定的 wave
檔:
Terminal » Bell » Set the style of the bell » Play a custom sound file

經過這麼一番設定,當有人呼喚妳的時候, Windows 就會發出提示音了。

Friday, August 29, 2008

VirtualBox 中共享文件夹的设置[转载]

如果你需要从 VirtualBox 的客户机中使用主机里面的文件,那么通过共享文件夹的方式可以达成此目的。就以我的实际情况为例(VirtualBox 主机为 Linux,客户机为 Windows XP),说说设置的过程。
在 VirtualBox 的主机(即 Linux 系统中)执行下列命令: 

VBoxManage sharedfolder add "VM name" -name "sharename" -hostpath "\test"

该命令中的 VM name 指定要使用共享文件夹的虚拟机名称,如 WinXP;sharename 为共享的文件夹名称,可任意设置,如 sharedfolder;\test 为主机上需要共享的文件夹。下面给出一个该命令的实例:

VBoxManage sharedfolder add "WinXP" -name "downloads" -hostpath "\home\xu\downloads"
启动虚拟机(本例为 Windows XP),点击开始菜单中的“运行”,并输入 cmd,然后执行以下指令: 

net use x: \\vboxsvr\sharename

这个指令中的 x: 为映射的驱动器符号;sharename 为上一步中所设置的共享文件夹名称。同样,我们给出一个实例供参考:

net use Z: \\vboxsvr\downloads


在命令成功执行后,通过资源管理器你便可以使用共享文件夹中的所有文件了。

在配置共享文件夹时,有几点需要注意:一是在配置时,不能开启或挂起虚拟机;二是要为客户机安装 VirtualBox Guest Additions 程序;三是共享文件夹只能用于 Windows 2000/XP 和 Linux 2.4/2.6 的客户机中。

另外,如果你的 VirtualBox 主机为 Windows,客户机为 Linux,也可按此法配置。不同的是,在执行第二个步骤时换成 mount 即可。

本文网址: http://linuxtoy.org/archives/configuring-virtualbox.html

《网络渗透技术》的完整版 下载

http://forum.eviloctal.com/read-htm-tid-22710.html

以前only_over发过,可惜307页到600多页没有。
后来linuxfans有下载的。结果183页之前都没有。
我就把两个合到一起,整理了个完整的版本。


《网络渗透技术》一书的说明 介绍
http://www.xfocus.net/projects/book/9.html

《网络渗透技术》配套资料 在这里
http://www.xfocus.net/projects/book/npt/

《网络渗透技术》配套资料打包
http://www.xfocus.net/projects/book/npt/npt.rar

此书为PDG格式 PDG文件浏览器从这里下载 http://www.skycn.com/soft/3089.html

在此本人代表所有阅读者
感谢本书的创作团队安全焦点和所有参与本书创作发行以及为此书做过贡献的同志

Thursday, August 28, 2008

rxvt下的复制与粘贴

在rxvt下按右键是没有响应的,也无法通过常规的Ctrl+C/Ctrl+V来进行复制粘贴。其实,在Linux中的X下,只要选中某段字符串,该字符串就会被自动复制到Clipboard,然后通过鼠标中键即可完成粘贴操作。

Wednesday, August 27, 2008

用screen + irssi上irc之乡民版教学(含Q&A)

最近身旁許多在上 IRC (Internet Relay Chat)的朋友都問我哪個IRC client 比較好用?其實,只要問過我的,而且又是UNIX-like的系統使用者時,基本上都會被我推薦irssi這個command mode的純文字IRC程式。若有server可用的朋友們,更是會被我力推screen + irssi的組合。好處是,可以遠端持續掛著IRC,到哪邊都可以ssh進去繼續看IRC log,這樣真的很方便,也不用擔心因為沒開自己的電腦,就看不到別人的對話或別人要留給自己的訊息。

以下是針對irssi這軟體所寫的簡易基本介紹與使用和一些需要使用到IRC與GNU screen的基本指令,如需IRC或screen的其他更詳細指令與資料,文末會補上相關連結,如有不足,歡迎補充。

irssi的程式安裝不贅述,可由apt-get或yum等工具自套件庫裡面找尋並安裝。

先在這邊建立第一次使用screen + irssi操作IRC的朋友們觀念,確定遇到的問題跟操作,該是由screen還是由irssi的程式部份來處理,或者本身只是IRC上的指令操作罷了。screen只是方便讓使用者可以利用server不關機的優勢,讓irssi可以連續開著不中斷,使得下次再透過screen來接軌回到上次開啟還未被關閉的irssi來繼續IRC這樣子。所以,這樣看下面的簡介操作後比較不會搞混狀況,如果請教朋友也比較能問到問題處。

以下例子皆以irssi 0.8.10或以上版本,經實驗都可順利執行,且都以在FreeNode上的#orzlab IRC channel 為例。

(如果不掛 screen 者,這一段請直接跳過) 首先ssh login到server後,請輸入:
screen -RD
-R Reattach if possible, otherwise start a new session.
-D (-r) Detach and logout remote (and reattach here).
然後會進入到新開啟的screen,並且screen會自動開啟一個新的window讓我們使用,接下來直接輸入:
irssi
就會在screen底下的第一個視窗執行irssi這隻程式。

如果沒有要掛著screen執行irssi的朋友,那直接輸入
irssi
就可以直接執行 irssi 這隻程式。

進入irssi後,直接在提示輸入字元處輸入
/connect irc_server
就會直接連到該個IRC server,例如:
/connect irc.freenode.net
這樣就會直接連接到freenode的IRC server上,此時,可以先在這邊修改自己要在該IRC server 上的暱稱,如果要修改,則輸入以下格式:
/nick you_want_nickname
例如當我輸入
/nick lzy
時,那我顯示出來的暱稱將會是「lzy」的字樣( irssi 預設的暱稱會是 login 的使用者名稱)。
搞定暱稱後,接著我們就可以加入其他頻道了。
只要輸入
/j #channel_name
就可以直接加入了,例如:
/j #orzlab
這樣就完成加入#orzlab這個IRC channel(即OrzLab的主要IRC channel),如果該IRC channel需要key/password的話,則輸入:
/j #channel_name password
如果要離開單一IRC channel ,則直接輸入
/wc
就可以離開這個IRC頻道。
若是要離開一個IRC server的連線,則輸入
/disconnect irc_server_name

剛剛是教如何連線,現在則是教一些常用的熱鍵與功能。
先來看圖說故事一下:


上面的這張圖,我們在
[Act: 1,2,4,6,9,10]
這邊發現了幾個不一樣的標示數字,Act這一欄位會提示你在第幾編號的channel上對話狀況,而你還沒切換到該IRC channel 上觀看。顏色對應的意思如下:
  • 灰色一般體的是代表有人登入或登出此 irc channel (如 1,9,10)
  • 白色粗體的是代表有人正在此 irc channel 上談話(如 4,6)
  • 灰色粗體的則是有人在對話中提起你的名字或者呼叫你,總之就是有出現你的名字(如 2)
這是基本識別,再來是知道哪個channel有什麼狀況後,就是切換到該IRC channel上查看:
Alt + 1~0 對應 1~10 的 irc channel 編號;
Alt + q~p 對應 11~20 的 irc channel 編號;
Ctrl + n/p 可切換 上/下 一個 irc channel;
按鍵盤上的 PageUP/PageDn 可以直接切換 上/下 頁訊息。
如發現有編碼上的問題,需要轉編碼的話,則可輸入
/recode add #channel_name code_type
例如要把#orzlab的UTF-8格式加入,則輸入
/recode add #orzlab utf8
即可加入此頻道的編碼格式。
然後輸入
/recode
就可以看到加入的編碼列表。
(註:因 /recode add會寫入到設定檔裡,所以僅需要寫入一次即可)


Q&A TIME:

Q:如何同時有連接多個IRC server呢?又該怎樣切換不同IRC server來加入該server的IRC channel呢?
A:
請直接再下一次 /connect irc_server 就可以再連接一個新的 irc server ,然後按Alt + 1切換到第一個的特殊頻道上,再按 Ctrl + x來切換目前要下達指令的 IRC server名稱。

Q:如何查看該頻道的所有人呢?
A:
請下達/who的IRC指令即可,然後也是一樣按Alt + 1切換到第一個伺服器狀態頻道上觀看

Q:如何查看單一網友的基本連線資料呢?
A:
請下達/whois nickname的IRC指令即可,然後也是一樣按Alt + 1切換到第一個伺服器狀態頻道上觀看

Q:如何傳送私人訊息到指定的朋友暱稱呢?
A:
請下達/msg nickname即可開啟一個名為指定暱稱的訊息頻道,一樣用alt + 1~0/q~p 來選擇(注意:某些IRC server 會限制此功能,傳訊前請先確認是否有權限,如FreeNode)。
Q:已使用上面所講的方式操作screen + irssi ,那我離開時,是否得下達任何參數或指令?又下次ssh login 後,需要打什麼指令呢?
A:
為了簡化登入與記憶上的方面,採用-RD的參數,所以每次要離開irssi時,直接關閉該視窗就好,不需下達任何參數或指令。然後下一次ssh login後,只要打screen -RD 這樣就可以接軌回上次開啟的irssi了。

Q:如果遠端連線到編碼為Big5 的主機掛screen + irssi,且client端是採用UTF-8編碼時,編碼的亂碼問題如何處理?
A:
首先,先處理screen的編碼問題,從utf8端要檢視big5 server時,先Ctrl + a,然後輸入 :encoding big5 utf8 ,把從server將送出的Big5編碼先轉成UTF-8後再送出,然後輸入 "/recode" 觀看頻道編碼是否指定正確,照上述設定,理應能順利顯示。

Q:如果不小心按到Ctrl + z或鍵盤上的Pause時, irssi被suspend了,該如何恢復?
A:
請直接輸入fg後按Enter ,就可以把剛剛被suspend的irssi給喚醒。

Q:如果我要關閉一個irssi,該如何下達指令?
A:
請直接關閉開啟irssi的screen ,請按Ctrl + k來關閉screen window,然後可以再重新開啟一個全新的 rssi出來。

Q:要如何自動儲存IRC log ?
A:
在需要auto irc log的IRC channel上輸入/SET autolog ON,即可打開autolog功能。

Q:要如何指定當開啟irssi後,自動連接IRC server與自動連接IRC channel ?
A:
直接看例子會比較快,先假設我要讓他自動用 lzy 的暱稱連接到Freenode的IRC server 上的#orzlab:
/network add -nick lzy Freenode
/server add -auto -network Freenode irc.freenode.net 7000
/channel add -auto #orzlab Freenode

如果是需要key/password的IRC channel的話,則把最後一行改為
/channel add -auto #irc_channel_name irc_server_name password
也就是直接把密碼接在後面就可以了
如果需要自動對註冊的暱稱進行認證登入的話 (設口令為abcde):
/network add -autosendcmd "/^msg nickserv ident abcde;wait 2000" Freenode

Q:如何讓irssi發出有人提起自己暱稱時的訊息警告(或響鈴)?
A:
在irssi裡輸入以下指令,讓irssi適時發出聲音訊號:
/set beep_when_window_active ON
/set beep_when_away ON
/set beep_msg_level MSGS NOTICES DCC DCCMSGS HILIGHT
/set bell_beeps ON

在screen中按下Ctrl +a , Ctrl + g的按鍵,讓screen把irssi發出來的聲音訊號傳出來
或參考Jedi的blog一文「會響的 PuTTY + screen + irssi
Q:如何更換irssi的theme ?
A:
把抓好的 theme(可從官網選擇偏好的),然後複製該theme的檔案到~/.irssi/路徑,並下達/SET theme theme_name來更改該 theme 。

Q:如何自訂irssi的IRC訊息熱鍵?
A:
因為設定比較繁雜,故只提供官網網址,讓有興趣的朋友可以自己去翻閱。

提供幾個額外補充的網站,沒標示語言者,皆為中文
※本文另有較鄉民版本:「用 screen + irssi 上 irc 之鄉民版教學 (含Q&A)

Saturday, August 9, 2008

HOWTO: Multiple local XFree users under Linux Multiple Local XFree Users Under Linux

HOWTO: Multiple local XFree users under Linux
Multiple Local XFree Users Under Linux

Linux HOWTOs
Thursday, March 15, 2001 12:39:54 PM

Multiple local XFree users under Linux 

Version 0.9 by Miguel Freitas  

January 16, 2001




Keywords (for bots) 

I've wasted a lot of time trying to find this kind of document in google, hotbot and so on. Let me add some keywords to help people finding it: true dual-head, multi-user support, XFree86 4.0, multiple keyboard, multiple mouse, multiple video card, dual user, XFree86 instances, dual keyboard, USB keyboard under X. 
  

Motivation 
  

I have one girlfriend and one computer. In normal conditions, we both couldn't use the computer at the same time, in spite of the fact that it usually has a lot of processing power available. I also have a spare monitor and a second video card for playing 3D games (voodoo) so this idea came to me as something very obvious. New XFree86 4.0 support for dualhead suggests that most of the hard work is already done. And it has to be on Linux, because no closed source OS would allow me to make the changes that I need. 

As several reports confirm, Linux is been successfully used in educational institutions and projects due to it's great benefits and low cost. Using the same computer for two (or more) simultaneous students, workers, etc. is something that can reduce even more these costs. 

This is also a great option for companies to simplify the management and upgrades of the shared resources (motherboard, processor, hds). 

For everybody who may be asking: don't it get too slow? No. The performance difference is barely perceptible as most of the time the computer is waiting some command from the user. And if you haven't figured it out by yourself let me tell something: we live in a time of computing power in excess or do you think most of the users needs a GigaHertz Pentium 3 machine just to do their word processing and surf the web? 
  

Problems 
  

There are some problems that need to be addressed in order to support multiple XFree instances (and users): 
VT handling - The Linux kernel Virtual Terminal scheme is a great hack these days. It used to be good in the past as a way to have multiple screens, but now it's something that needs to be completely rewritten (several Linux developers have shown interest in developing a better scheme for 2.5.x series). The main issue is that VT code doesn't understand that we may have multiple input and output devices which therefore may be completely independent. There's no way to associate a given set of VTs for each hardware so Linux kernel would know which VTs can be used simultaneously. If we dispatch multiple instances of XFree86 they would be on different VTs and the Linux kernel will inform them of all VT switching stuff. A switched out (graphic) VT must not use the hardware as it would normally mess with the other active VT, but this is no more true as we have two independent video cards.
Keyboard support - Multiple mouses on X are already a reality as we may specify the "device" option for each one. Unfortunately, the keyboard driver is still deeply rooted at XFree86 core, it's not a separated module and access console I/O functions to read the scancodes. Each XFree86 instance would have their keyboard access halted by VT switching. Besides, Linux is still lacking support for multiple keyboards in a well defined way. Let's wait for 2.5.x tree to see what will be done...
My solution 

My hack is surely not the best one, I know thousands of things that could be better implemented in XFree86 and Linux Kernel to support true dual-head (and dual-input) in a clean way. But it works for me. Don't blame me if you spend your money and time buying videocards, monitors, keyboards, mouses and it doesn't work. You've been warned. 

Although I would love to see XFree86 supporting simultaneous layouts (without another instance) and a brand new keyboard driver, I don't have the necessary understanding of the project to implement it by myself. Anyway, my regards to the XFree86 developers for this great piece of software! 

My idea is to have two instances of XFree86. The first will be using a normal XFree86 server, it will initialize the main video card and attach it to a VT. It will also use the standard system AT keyboard and something (PS/2, serial, USB emulated as PS/2, whatever you want) as a mouse. 

The second instance of XFree will be my modified X server. It does not support VT switching at all because it's been used to control a hardware that is not normally used by any other VT. Read my lips, this is very important: The video card can't be the primary one, the mouse can't be the same used by gpm and the keyboard must be USB and must not generate scancodes to the normal Linux console! 

As the keyboard doesn't look like a normal AT keyboard (no keys to standard console) the keyboard driver of my modified X server must take care of USB events translating them to normal scancodes. 
  

Procedure (step by step) 
  

1) You need to get XFree 4.0.x (RedHat 7.0 and a lot of recent distros comes with it) and configure it for two video cards and monitors. I suggest that you first try it with Xinerama extension following this HowTo: http://linuxdocs.org/HOWTOs/Xinerama-HOWTO.html 

Then modify your XF86Config or XF86Config-4 to separate your screens in two layouts, instead of using them with Xinerama extension. Don't know what I am talking about? Then it's time to read XF86Config, do a ``man XF86Config'' 

With two layouts your XF86Config should look like this: 
  

Section "ServerLayout"
  Identifier "Layout0"
  Screen 0 "Screen0"
  InputDevice "Mouse0" "CorePointer"
  InputDevice "Keyboard0" "CoreKeyboard"
EndSection

Section "ServerLayout"
  Identifier "Layout1"
  Screen 0 "Screen1"
  InputDevice "Mouse0" "CorePointer"
  InputDevice "Keyboard0" "CoreKeyboard"
EndSection

Section "InputDevice"
  Identifier "Keyboard0"
  Driver "keyboard"
  # this is for supporting deadkeys
  Option "XkbRules" "xfree86"
  Option "XkbModel" "us"
  Option "XkbLayout" "br"
EndSection

Section "InputDevice"
  Identifier "Mouse0"
  Driver "mouse"
  Option "Device" "/dev/mouse"
  Option "Protocol" "IMPS/2"
  Option "Emulate3Buttons" "off"
  Option "ZAxisMapping" "4 5"
EndSection

Section "Monitor"
  Identifier "Plex17"
  VendorName "Unknown"
  ModelName "Unknown"
  HorizSync 31.5 - 79.0
  VertRefresh 50-90
EndSection

Section "Monitor"
  Identifier "Syncmaster3"
  HorizSync 31.5 - 79.0
  VertRefresh 50-70
EndSection

Section "Device"
  Identifier "FireGL 1000 PRO"
  Driver "glint"
  BusID "pci:1:0:0"
  BoardName "Unknown"
EndSection

Section "Device"
  Identifier "Voodoo"
  Driver "glide"
  BusID "pci:0:12:0"
EndSection

Section "Screen"
  Identifier "Screen0"
  Device "FireGL 1000 PRO"
  Monitor "Plex17"
  DefaultDepth 16
  Subsection "Display"
  Depth 16
  Modes "1024x768"
  EndSubSection
EndSection

Section "Screen"
  Identifier "Screen1"
  Device "Voodoo"
  Monitor "SyncMaster 3"
  DefaultDepth 16
  SubSection "Display"
  Depth 16
  Modes "800x600"
  EndSubSection
EndSection

This should be trivial to do because it's almost the same as Xinerama configuration but with two layouts. Then switch your box to runlevel 3 (init 3) and try both layouts, one at a time: 

# XFree86 -layout Layout0
# XFree86 -layout Layout1

Pay attention to BusID settings as described in howto. Note that a dualhead board (like Matrox G400) should NOT work through the next steps, as we will be using 2 instances talking to the same hardware. But I haven't tried myself (I'd be happy to try it if any reader wants to donate such video card...). 

Not all video cards can be used with XFree86 dualhead support. Don't email me saying that you couldn't get your cards to work up to here or you will burn in hell! Read the Xinerama HowTo instead, thanks. 
  

2) Plug your second mouse on the system and configure XF86Config to use it in the second layout. This mouse must not be used by any other program, like gpm. XF86Config will look like this (only the changed sections): 

Section "ServerLayout"
  Identifier "Layout1"
  Screen 0 "Screen1"
  InputDevice "Mouse1" "CorePointer"
  InputDevice "Keyboard0" "CoreKeyboard"
EndSection

 
Section "InputDevice"
  Identifier "Mouse1"
  Driver "mouse"
  Option "Device" "/dev/ttyS1"
  Option "Protocol" "Microsoft"
EndSection
 
Again, test this layout to make sure it's working. 
  

3) Get Linux Kernel 2.4.0 so we can play with USB support. Some 2.2.x kernels may work as they have backported USB support, but in doubt, stick with 2.4.0. 

In the kernel configuration, enable USB support (CONFIG_USB) and keyboard (either CONFIG_USB_HID or CONFIG_USB_KBD if your don't need USB mouse support). You must enable "input core support" (CONFIG_INPUT) and MUST NOT enable "keyboard support" (CONFIG_INPUT_KEYBDEV) as we don't want the USB one to be the system keyboard. Also enable "event interface" (CONFIG_INPUT_EVDEV) as I will use it to receive scancodes. 

Compile and install the kernel. Now plug your USB keyboard, once the kernel enters you should not see any pressed keys from it at the console. Now try reading the keyboard events (assuming the keyboard is the only USB device you have): 

# cat /dev/input/event0

You should see some garbage on the screen as you type. That's all right, your keyboard is working. If you don't see anything or get "No such device", something is wrong with your USB system. Read Documentation/usb in your kernel sources for more information. 
  

4) Get the sources of your XFree86 4.0.x if you haven't already done so. The sources are available from www.xfree86.org. There should be 3 or 4 big .tgz files, but you will only need the first one. 

Expand the tree and apply my patch, which can be downloaded here (4.0.1) and here (4.0.2). Follow the instructions from the package to build the X server (make World). You should get a new XFree86 executable on directory xc/programs/Xserver. Copy it to your /usr/X11R6/bin with another name (like XFree86-2nd). 

Or if you like the easy way, try one of my XFree86-2nd servers (compiled against glibc-2.1): 

XFree86-4.0.1-2nd.gz 

XFree86-4.0.2-2nd.gz 

This server supports only USB keyboards and do not grab a VT. The only VT code it has is to switch to a given console through XFree86-2nd vtxx parameter. 

Applying the patch is intended only for developers that can help me improving this scheme. It will also require you hundreds of MB of disk space. If my provided X servers doesn't work with your system there's little I can do about it. If you can, try to discover the problem and fix it. 
  

5) Modify the second layout to use the USB keyboard. This will require you to use the protocol "usbev" I created and specify the /dev/input/eventx you like as the device. The XF86Config should now look like this (only the changed sections): 

Section "ServerLayout"
  Identifier "Layout1"
  Screen 0 "Screen1"
  InputDevice "Mouse1" "CorePointer"
  InputDevice "Keyboard1" "CoreKeyboard"
EndSection
 
Section "InputDevice"
  Identifier "Keyboard1"
  Driver "keyboard"
  Option "Protocol" "usbev"
  Option "Device" "/dev/input/event0"
EndSection
 
Now try this X server with the command: 

# XFree86-2nd -layout Layout1 

It should initialize your second video card, the second mouse and the usb keyboard without interfering with your console. You can even do this from a xterm window inside your running X server. Yes! It works! Now move on to the grand finale... 
  

6) If you use gdm as display manager and to provide you a graphical login, you can edit the file /etc/X11/gdm/gdm.conf as follows: 

[servers]
0=/usr/bin/X11/XFree86-2nd -delay -layout layout1 vt07
1=/usr/bin/X11/X vt07

Getting this one to work may be a major challenge. It took me a lot of trial and error until I got this stable configuration. I had to add a option "-delay" (my hack) to cause a 10 second delay at one of the servers so they would not initialize the hardware at the same time. I don't know why this is needed. Playing with the order they are initialized (by exchanging 0= and 1=) also does the trick. 
  

Known Bugs 
  

This thing mess up with my text console. I have to switch between the VTs a couple of times before the text looks good again. Fell free to give me a solution. 

Also a main problem may be that the whole thing does not work with other hardware and you may be wasting your time reading all this. But the idea is here and I can guarantee that it worked for me. So it must be some little issue that I'm sure will be quickly resolved by another developer somewhere.... 
  

Updates 

Price study

Brad Midgley pointed that support for Matrox G400 and similar dualhead cards should be possible using framebuffer interface. I still don't have the hardware to do any tests on this, but if you want to try please note that I may have removed something important for framebuffer from the init routines. Please check for any mistakes the patch might have. Any updates on this issue are greatly appreciated... 
  

Contact 
  

Miguel Freitas
Center for Telecommunications Studies of the
Catholic University of Rio de Janeiro (CETUC/PUC-Rio)
Brazil