Posterous theme by Cory Watilo

Filed under: computer

[linux] compiling winexe

compiling winexe on "try Ubuntu".

 

ubuntu 12.04. http://www.ubuntu.com/download

winexe http://sourceforge.net/projects/winexe/

 

$ sudo view /etc/apt/sources.list

deb http://archive.ubuntu.com/ubuntu/ precise-updates main restricted

copy and change "deb" to "deb-src"

deb-src http://archive.ubuntu.com/ubuntu/ precise-updates main restricted

 

$ sudo apt-get update

$ sudo apt-get build-essential install autoconf python-dev

$ ./autogen.sh

$ ./configure

$ make basics

$ make proto bin/winexe

$ ./bin/winexe -V

Version 4.0.0alpha11-GIT-UNKNOWN

[memo] git tips.

gitに関するメモ用Link

 

))) Git初心者が絶対に覚えておくべきコマンド

http://d.hatena.ne.jp/idesaku/20091106/1257507849

 

))) git reset についてもまとめてみる

http://d.hatena.ne.jp/murank/20110327/1301224770

 

))) gitで共用リポジトリにpushした変更を取り消す。

http://d.hatena.ne.jp/shunsuk/20101202/1291278345

 

))) Gitのコミットを間違えたときの対処法まとめ

http://d.hatena.ne.jp/keisukefukuda/20111105/p1

 

))) Denying non-fast-forward and SourceForge

http://pete.akeo.ie/2011/02/denying-non-fast-forward-and.html

[linux] convert csv to sqlite

日付別csvを作ってみてたが、データベースにつっこもうと思い、sqliteにコンバート

 

))) logs/2011/0404.csv.gz

58.215.240.72,TCP,6000,3389,06:25:06

 

))) log.schema

CREATE TABLE fw (
  id integer PRIMARY KEY,
  ip varchar(15),
  date datetime,
  proto varchar(3),
  spt integer,
  dpt integer
);

 

))) convert.sh

#!/bin/bash

echo "begin;" > insert.sql

date

for file in `ls logs/*/*.csv.gz`
do
  array=(`echo $file | sed -e 's/.*\/\(201[1,2]\)\/\([0,1][0-9]\)\([0-3][0-9]\).*/\1 \2 \3/'`)
  gzip -dc $file | awk -F, -v year=${array[0]} -v month=${array[1]} -v date=${array[2]} '{print "insert into fw values(NULL,\x27"$1"\x27,\x27"year"-"month"-"date" "$5"\x27,\x27"$2"\x27,"$3","$4");"}' >> insert.sql
done

echo "commit;" >> insert.sql
date

sqlite log.sqlite < log.schema
sqlite log.sqlite < insert.sql
date

 

[memo] shell tips

shellでいろいろやったときのメモ

 

))) use ":"

$ echo ${name:-value}
value
$ echo $name

 

$ echo ${name:=value}
value
$ echo $name
value

 

))) rename error.log.1.gz to error.log.YYYYMMDD.gz

LANG=C
type=error.log
for file in $(ls $type.*.gz); do dd=$(ls -l $file | awk '{print $6}' | sed -e s'/-//g'); mv $file $type.$dd.gz; done

 

))) awk: variable

$ line="May 3 13:48:35 SRC=192.168.1.1 DST=192.168.1.2 PROTO=TCP SPT=8888 DPT=9999"
$ MONTH=May
$ DATE=3
$ echo $line | \
awk -v month=$MONTH -v date=$DATE '{
 if ( $1 == month && $2 == date ) {
  print $3,$4,$5,$6,$7,$8
 }
}'
13:48:35 SRC=192.168.1.1 DST=192.168.1.2 PROTO=TCP SPT=8888 DPT=9999

 

))) awk: single quote

$ echo "192.168.58.1 0a:00:27:00:00:00" | \
awk '{print "insert into arp values(\x27"$1"\x27,\x27"$2"\x27);"}'
insert into arp values('192.168.58.1','0a:00:27:00:00:00');

 

[linux] daily logging with syslog-ng

syslogで日付毎に自動でログファイルを作成させる。

options {
  owner(root) group(root) perm(0600) dir_perm(0700) create_dirs(yes)); 
}

destination d_local { file("/var/log/local/$YEAR/$MONTH/$DAY/$FACILITY-$LEVEL.log"); };

 

そのままにしておくとログディレクトリが容量を圧迫していくので、findで毎日圧縮するのがよい。

find /var/log/local -type f -not -path "$(date "+*/%Y/%m/%d/*")" -name "*.log" | xargs lzma

[Linux] SpiderOakの使い方 - how to use SpiderOak

SpierOakをheadlessで使うためにいろいろやったメモ

use MacBook(Desktop Client) and Debian(headless)

(hint: How do I install SpiderOak on a headless Linux server? )

 

))) アカウント作成 on MacBook - Sign Up on MacBook

公式サイトから直接サインアップすると2GBしかもらえないので、SpiderOakをお勧めしているブログなどのURLを探してクリックする。

 - find the web site introduce SpiderOak and click refferal link.

ex) https://spideroak.com/download/referral/6cff174dd132607bf9a774699ccd556f

完全にheadless Linuxのみで利用する場合は、How do I set up a new user from the commandline? を参考に New User Setup から作成すること。

* if you don't use desktop client (headless linux only), signup from New User Setup. refer How do I set up a new user from the commandline?.

 

))) SpiderOakのセットアップ on MacBook - setup SpiderOak on MacBook

サインアップすると自動的にダウンロードが開始されるので、インストールしてログイン - sign up, download the software, install it, and login.

 

))) SpierOak for debian のダウンロード

当初 APT sources for Linux を参考にして、リポジトリを追加してみたけど、リリースされているバージョンより古かったのでやっぱりやめに。 - because of the release version at apt is old, I got from download link.

$ wget "https://spideroak.com/directdownload?platform=ubuntulucid&arch=x86_64"
--2011-12-19 12:56:56--  https://spideroak.com/directdownload?platform=ubuntulucid&arch=x86_64
Resolving spideroak.com... 208.28.15.128
Connecting to spideroak.com|208.28.15.128|:443... connected.
ERROR: cannot verify spideroak.com's certificate, issued by `/C=US/O=GeoTrust, Inc./CN=RapidSSL CA': 
  Unable to locally verify the issuer's authority.
To connect to spideroak.com insecurely, use `--no-check-certificate'

RapidSSLダメみたいね〜。仕方がないのでエラーメッセージの通りに -no-check-certificate をつける - download again with "-no-check-certificate" option.

$ wget --no-check-certificate "https://spideroak.com/directdownload?platform=ubuntulucid&arch=x86_64"

で spideroak_9909_amd64.deb ファイルをゲット

 

))) SpiderOakのインストールに必要なモジュールをインストール - install module

$ sudo apt-get install  libdbus-1-3 dbus libxrender1

 

))) SpierOakをインストール - install SpiderOak

$ sudo dpkg -i spideroak_9909_amd64.deb

 

))) newusersetup.js の作成 - create newusersetup.js

How do I set up a new user from the commandline?

To add a device to an existing account: use the new device setup form, then edit the resulting file in a text editor (as directed in the previous paragraph), replacing the text "ENTER YOUR PASSWORD HERE" with your account password, before using the --bootstrap option.

を参考に https://spideroak.com/nus/console?newdevice=yes にアクセスし、ユーザー名とデバイス名を入力して、newusersetup.jsをダウンロード

newusersetup.js をテキストエディタ等で開いて "ENTER YOUR PASSWORD HERE" をアカウント作成時のパスワードと置換

 

))) SpiderOakのセットアップ - setup SpiderOak

$ SpiderOak --bootstrap=newusersetup.js

 

))) ターゲットディレクトリをすべてバックアップする場合 - backup entire directory

$ SpiderOak --backup=/var/backup

 

))) ターゲットディレクトリに除外するディレクトリがある場合 - backup directory without some directory

--includeでターゲットを指定 - specify directory with "--include"

$ SpiderOak --include-dir=/home/onoh

--exclude-dirで除外ディレクトリを指定 - exclude directory with "--exclude"

$ SpiderOak --exclude-dir=/home/onoh/tmp

バックアップの実行 - do backup

$ SpiderOak --batchmode

 

))) cron

$ sudo view /etc/cron.daily/spideroak
#!/bin/sh
usr/bin/spideroak --batchmode > /dev/null 2>&1
$ sudo chmod +x /etc/cron.daily/spideroak

 

))) Memo

:SpiderOakの設定ファイルやログなどは

Linux: ~/.SpiderOak
Mac: ~/Library/Application Support/SpiderOak

コピーや移動で、ディレクトリを空にすればまた新たにセットアップから始まるので、複数のアカウントに切り替えも可能

 

:syncはAとBを全く同期させるので、いったん同期が完了するとBでファイルを削除するとAにも反映される

常にAをmasterとしてBをいじったとしても反映されないといった設定はできない様子

 

[memo] ssh config example

config example

))) LocalForward

"172.16.1.1:22001" and "10.1.1.1:11008" is accessible by "192.168.1.1" only.

Host step
 Hostname 192.168.1.1
 User user
 LocalForward 22221 172.16.1.1:22001
 LocalForward 22222 10.1.1.1:11008

Host server1
 HostName 127.0.0.1
 Port 22221
 User user1

Host server2
 HostName 127.0.0.1
 Port 22222
 User user2

))) same as

ssh -L 22221:172.16.1.1:22001 -L 22222:10.1.1.1:11008 user@192.168.1.1

))) use

  1. ssh step
  2. ssh server1 ( other console )
  3. ssh server2 ( other console )

))) debug sample

ssh -v step
debug1: Local connections to LOCALHOST:22221 forwarded to remote address 172.16.1.1:22001
debug1: Local forwarding listening on 127.0.0.1 port 22221.
debug1: Local connections to LOCALHOST:22222 forwarded to remote address 10.1.1.1:11008
debug1: Local forwarding listening on 127.0.0.1 port 22222.

 

[linux] sshをiptablesで制限する(without hitcount)

会社のほうで VPS(Virtual Private Server) を契約していて、毎回リモートコンソールで接続するのは面倒なので、やっぱりSSHで接続することになる

んで、調べてみると(というか iptables ssh で検索すると)

「sshへの総当り攻撃をiptablesの2行で防ぐ方法」とか「iptables の ipt_recent で ssh の brute force attack 対策 」いろいろでてくる

んで、たいてい提唱しているルールはこんな感じ

-A INPUT -p tcp --dport 22 -m state --state NEW -m recent --set --name SSH
-A INPUT -p tcp --dport 22 -m state --state NEW -m recent --update --seconds 60 --hitcount 3 --rttl --name SSH -j DROP

過去60秒の間に、SSHへの接続を3回試してきたらDROPする

 

なんとなく分かるけど、こちとらSSHのプロンプトすら見せたくないので、こういうふうにした

-A INPUT -p tcp -m tcp --dport 22222 -m recent --set --name check --rsource -j DROP
-A INPUT -p tcp -m tcp --dport 22 -m state --state NEW -m recent --rcheck --seconds 3 --name check --rsource -j ACCEPT

SSHへの接続をしてきた時に、過去3秒の間に22222ポートへのTCP接続があれば、そのIPアドレスからのSSHへの接続を許可する

実際に接続するときには3秒以内に 22222ポートへTCP接続して、22ポートへSSH接続しないとダメなので

$ ssh dummy; ssh target

とし、dummyへの接続は config(~/.ssh/config)で

Host dummy
Port 22222
ConnectTimeout 1

1秒たったら接続を遮断して、すぐに target にSSH接続するようにしている

ちなみにこれはTCP接続にしているけど、別にICMPでもUDPでも他のTCPでも何でもいいし、もっと短くできるなら1秒にしちゃってもいい

 

もちろん、多くの文献にあるように接続回数が多い場合に遮断するのもわかるけど、sshdにセキュリティホールが見つかるかもしれないので、やっぱり使いたくない

[linux] tinyproxy filter

sample settings for tinyproxy with filter

 

/etc/tinyproxy.conf

Filter /etc/filter
FilterURLs on
FilterExtended On
FilterCaseSensitive On
FilterdefaultDeny No

 

bad

google.com

tinyproxy refused these urls

x : http://google.com

x : http://example.com/google.com/

x : http://example.com/googleacom/

 

good 

^http://google¥.com

x : http://google.com

o : http://example.com/google.com/

 

https with name

google¥.com:443

x : https://google.com/

o : https://74.125.31.147/

at Log

Request : CONNECT google.com:443 HTTP/1.1
Proxying refused on filtered url "google.com:443"

 

https with name and ip address

google¥.com:443 74¥.125¥.31¥.147:443

x : https://google.com/

x : https://74.125.31.147/

at Log

Request : CONNECT google.com:443 HTTP/1.1
Proxying refused on filtered url "google.com:443"
Request : CONNECT 74.125.31.147:443 HTTP/1.1
Proxying refused on filtered url "74.125.31.147:443"

 

notice

when "nslookup / dig" "google.example.com" returns "74.125.31.147"

you can access "74.125.31.147" by "http://google.example.com/" or https://google.example.com/" with certification error.