AbiusX

official website of Abbas Naderi

L2TP on Ubuntu 10.04 LTS

VN:F [1.9.5_1105]
امتیاز: ۰ (از ۲ رای)

This post is a tutorial on how to run a L2TP over IPSec VPN Server for proxy purposes on a Ubuntu 10.04 LTS Server machine. Before we start the practice, let us review some theories:

What is VPN?

Virtual Private Network, is a technology, mainly developed to provide creation of virtual local networks with a wide geographic distribution. For example, we have a data-center and a considerable network in Bandar Abbas that requires constant maintenance and connectivity to our main servers and offices back in Tehran. We need a local network which consists of our office networks and the Bandar Abbas network, but since they are geographically distributed, we can’t have them local, so we cheat and virtually create a private (local) network, hence VPN.

Specifically speaking, we start a VPN server on our Bandar Abbas hub server (main.rajaei.abx.ir), then create a VPN connection from our computer (or router) and connect to it, and it would be like we have just plugged an Ethernet cable into our system, directly connected to whole Bandar Abbas network. After that we could simply connect to our surveillance server at 192.168.0.220 (which is a Bandar Abbas network IP, not ours) via any application.

As you might’ve already guessed, since VPN is usually established over the Internet, the most important thing to expect is data transmission security. No third party on the route should be able to sniff on our corporates data, right? VPN security is almost the main issue.

Then what is PPTP, L2TP, IPSec, SSTP, etc. ?

VPN, is a concept. It’s also a technology, but many protocols and mixtures of technologies tend to provide such means. The simplest form is PPTP, the point to point tunneling protocol. It is easily established, easily connected and fast. To setup a PPTP server on Ubuntu, you need less than 5 minutes. The problem with PPTP is data encryption. To encrypt data with PPTP, both parties (VPN Client and Server) have to agree on an encryption key, and any hacker listening while they are discussing it, would be able to read their transfers.

Then there comes OpenVPN, which is totally open source and good, but since there’s no native client on Windows, no body actually uses it. SSTP is also only Windows based, which is based on SSL Tunnels, very like the IPSec underlying layer of L2TP.

The other mostly used VPN technology, is L2TP, which relies on IPSec (lower network layer protocol) for its security. IPSec is a protocol which uses PKI (Public Key Infrastructure), or PSK (Pre-Shared Keys) which both are means to establish Zero-Knowledge connections securely without a third party being able to guess the password.

L2TP is technically called L2TP over IPSec, which is because first IPSec establishes a secure connection between two systems, then layer 2 tunneling protocol takes over for the networking and VPN functionality.

VPN as a means of proxy

In many cases, VPN is used for bypassing certain limitations and/or privacy, as proxy servers are used. Since VPN establishes a low level networking, proxies based on a VPN proxy all sorts of network connections, not just the web or videos. Anything, from peer to peer connections to DNS lookups are performed over the VPN.

To use a VPN for proxy purpose, we simply need to connect to a VPN far away (usually outside filtering region, if we are trying to bypass regional filtering) and use their internet connection. It is as if out Internet gateway, is not our own modem, but the computer over at the VPN.

VPN technologies (all PPTP, L2TP, SSTP, OpenVPN, etc.) work on certain ports and use certain traceable technologies. So blocking VPN usage is pretty simple, as PPTP no longer works more than a few seconds in Iran.

But with SSTP and L2TP, since both use a lower level encryption methodology (IPSec for L2TP), they can not be easily blocked. You might think that it would be pretty easy to prevent all IPSec connections and thus stop L2TP, as well as SSL for SSTP, but the case is, IPSec and SSL are used for all forms of encryption. When you use a banking service on the Internet, you employ SSL. When you transfer a file securely over the network, you employ IPSec. Blocking them would stop half of the Internet functionality.

There’s also no way of peeking into IPSec or SSL encrypted data (which contain the actual VPN packets), hence L2TP and SSTP services could not be stopped that easily.

Lets get dirty

Read the rest of this entry »

VN:F [1.9.5_1105]
امتیاز: ۱۰٫۰/۱۰ (۱ رای)

The Cynic and the Condemned

VN:F [1.9.5_1105]
امتیاز: (از ۴ رای)

Well, I know for a fact that I’m a cynic. But I wanted to have a definition for it, so I took a peek at the Internet. The sweet Wikipedia had some definition, totally irrelevant of the popular culture, based on some old Greek Philosophy practicing Areté.

Finally I found some interesting matching definitions on wiki.answers.com :

What is the difference between a cynic and an idealist?

A cynic is someone who fails to thrive, who picks apart good ideas and has a tendency to make life boring and miserable for himself and others. They do not see the purpose of success. They do not get excited. They do not understand where the passion of others comes from. Idealists are dreamers of success and have a potential to succeed. They have grand dreams of things they are interested in and work hard to see them come to light. If they fail, they can quite easily become cynics themselves. Many might argue that a cynic is simply an idealist who has experienced failure. In other words, you must first be an idealist before you have the capacity to be cynical.

And also, a few interesting quotes on the subject, which I really enjoyed :

“The cynic is one who never sees a good quality in a man, and never fails to see a bad one. He is the human owl, vigilant in darkness and blind to light, mousing for vermin, and never seeing noble game. The cynic puts all human actions into two classes – openly bad and secretly bad.” Henry Ward Beecher

“A cynic is a man who, when he smells flowers, looks around for a coffin.”
H. L. Mencken

“A cynic is not merely one who reads bitter lessons from the past, he is one who is prematurely disappointed in the future.” Sidney J. Harris

And for the end an example of a cynical statement:

“In the depths of my heart I can’t help being convinced that my dear fellow-men, with a few exceptions, are worthless.” Sigmund Freud

VN:F [1.9.5_1105]
امتیاز: ۱۰٫۰/۱۰ (۲ رای)

Why liberalism only suits US

VN:F [1.9.5_1105]
امتیاز: (از ۳ رای)

This is People’s Republic of China, an old man is headed into a banking establishment to do some everyday bank tasks. The bank is quite crowded, but after a few minutes it’s finally his turn to take up the booth. He  seems pretty slow with papers and also isn’t the sharpest when answering the bank employee’s questions, and this has been going on for a while.

The young lady who has entered the bank a few seconds after the old man, is growing impatient with the old man’s progress. She’s next, but it doesn’t seem like her turn will be coming up soon. Also, there aren’t any empty booths as there aren’t many functional booths available in the bank, and even if they were, they might’ve been occupied as well.

She couldn’t switch banks, since other banks are also pretty crowded and the switching process would probably consume more time than she’s gonna end up waiting for her turn in a lifetime of bank chores. After all, there are rarely enough banks for all of people in China, as in almost any other country.

While taking her time to wait, the bright women is fantasizing something in her head :

This is the United States, an old man goes into a bank to pay some bills. Since the bank is almost empty, as soon as he enters the bank, the booth accepts him. The man has around 30 bills and is quite slow doing paperwork, so he’s gonna take at least 45 minutes.

Another customer, a young woman also enters the bank. She seems impatient, and seeing the old man taking his time is boring her. Fortunately, there are plenty of other empty booths waiting for other customers, and even if there weren’t, she could easily switch banks and choose another eager one with plenty of room for new customers. After all, there are many more banks than people actually need in the US.

Liberalism is pretty delicious, ain’t it?

Thinking of all that, our lady realizes the old man has made only a little progress. She’s wondering what is the right thing to do in a situation like this, to put the old man at the back of the waiting line, since his task requires considerable time, or let him do whatever he requires in his own turn.

The second idea, however liberal it might sound, is starting to seem dull and inefficient to the lady, and amazingly the first one is the course of action she chooses as best fitting.

After all, Liberalism ain’t that suiting for everybody, is it?

VN:F [1.9.5_1105]
امتیاز: ۱۰٫۰/۱۰ (۴ رای)

نحوه فیلترینگ در ایران و نقاط ضعف آن

VN:F [1.9.5_1105]
امتیاز: +۱۳ (از ۱۹ رای)

امشب برای راه‌اندازی چندنوع پراکسی با تکنولوژی‌های مختلف، مجبور شدم نحوه کارکرد سیستم فیلترینگ ایران رو بررسی کنم و به نتایج خیلی جالبی رسیدم که خوبه شما هم بدونید :

اولا که فیلترینگ تنها بر روی وب (یعنی پروتکل‌های HTTP , HTTPs) پیاده شده و هیچ پروتکل دیگری فیلتر نیست، در حالی که فیلترینگی که آمریکا به دلیل محرومیت بر ایران اعمال کرده تمام پروتکل‌ها رو شامل می‌شه. اما قبل از اینکه ادامه فرآیند فیلترینگ رو بدونیم، لازمه بدونیم که چگونه یک سایت بر روی کامپیوتر ما لود می‌شه.

فرآیند بارگزاری یک سایت

به عنوان مثال فرض کنید آدرس www.facebook.com/profile/abiusx رو در کاوشگر وب خودتون وارد کردید (Internet Explorer یا Mozilla Firefox). کاوشگر شما این آدرس رو به آدرس کاملی که شما حوصله تایپش رو نداشتید تبدیل می‌کنه:

http://www.facebook.com/profile/abiusx

این آدرس نوع پروتکل رو نیز در بر داره (که پیش فرض وب هست) و به کاوشگر اجازه می‌ده نحوه باز کردن اون رو تشخیص بده. قبل از هر کاری، کاوشگر وب باید بدونه www.facebook.com بر روی کدوم کامپیوتر سرور روی اینترنت قرار داره، یعنی شماره اون کامپیوتر رو بدونه. این فرآیند توسط پروتکل زیرساختی DNS انجام می‌گیره که آدرس‌ها رو به شماره تبدیل می‌کنه.

نکته مهمی که بعدا به اون بر خواهیم خورد اینه که DNS ماهیت پرسش و پاسخی داره، یعنی کامپیوتر شما از کامپیوتر دیگری در شبکه (که معمولا ISP یا همون سرویس دهنده اینترنتتون هست) سوال می‌کنه که این آدرس شماره اش چنده؟ و پاسخ می‌گیره. بسیاری از فیلترینگ‌ها در دنیا در همین مرحله پیاده می‌شن، یعنی کامپیوتر بالادست به شما پاسخ می‌ده که این آدرسش ۱۰٫۱۰٫۳۴٫۳۴ هست (آدرس کامپیوتری که صفحه فیلترینگ روش قرار داره)، اما اینگونه فیلترینگ به سادگی قابل رفع هست. کافیه شما یک کامپیوتر خارج از ایران رو به عنوان DNS خودتون مشخص کنید، مثلا ۴٫۲٫۲٫۴ رو در تنظیمات اتصال به شبکه به عنوان آدرس کامپیوتر DNS خودتون وارد کنید و نگذارید که اتوماتیک مشخص شه. از این پس سوالات  DNS شما از این کامپیوتر پرسیده می‌شه و قاعدتا پاسخ‌های اون هم واقعی هستند و صفحه فیلترینگ نیستند.

همچنین باید توجه کرد که هر کامپیوتری در شبکه (اینترنت) که معمولا یک شماره داره، ممکنه یک یا چند سایت رو روی خودش سرویس دهی کنه. معمولا سایت‌های کوچک و کم مشتری بر روی کامپیوترهایی با چند سایت دیگر مشترک هستند، سایت‌های معمولی و پربازدید بر روی یک سرور اختصاصی با یک شماره هستند و سایت‌های معروف بر روی چندین سرور مختلف به صورت همزمان سرویس‌دهی می‌شوند.

برای درک این نسخه، برنامه ترمینال (Command Prompt) خود را باز کنید و دستورات زیر را وارد نمایید :

nslookup www.google.com

دستور فوق چندین شماره برمی‌گرداند، زیرا سایت گوگل بر روی چندین سرور مختلف سرویس دهی می‌شود

nslookup www.etebaran.ir

دستور فوق تنها یک شماره برمی‌گرداند زیرا این سایت بر روی یک سرور قرار دارد.

nslookup www.abiusx.com

nslookup www.etebaran.com

هر دوی دستورات زیر یک آدرس برمی‌گردانند، زیرا هردو سایت بالا بر روی یک کامپیوتر سرو می‌شوند.

پس از اینکه کاوشگر شماره کامپیوتر مقصد رو به دست آورد، یک اتصال شبکه از نوع TCP بر روی پورت ۸۰ (پورت مخصوص وب) برقرار می‌کنه و یک درخواست از نوع HTTP ارسال می‌کنه که جناب کامپیوتر مقصد، من فلان صفحه شمارو می‌خوام. قالب این درخواست متنی به صورت زیره :

GET http://www.facebook.com/profile/abiusx HTTP/1.1
Host: www.facebook.com
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.7; rv:5.0.1) Gecko/20100101 Firefox/5.0.1
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: en-us,en;q=0.5 Accept-Encoding: gzip, deflate Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
Cookie: PHPSESSID=9PmTx2exnapZfHmnegR9MsiPb2C00aDc6
If-Modified-Since: Sat, 30 Jul 2011 15:21:45 GMT
Cache-Control: max-age=0

این درخواست HTTP دارای اطلاعات خاصی است. برخی از خط‌های آن اختیاریست و برخی خط‌ها هم در بعضی درخواست‌ها وجود دارد که اینجا نیست. خط اول نوع درخواست (GET)، آدرس آن و نسخه پروتکل (۱٫۱)‌ را معین می‌سازد. این خط مهمترین خط است و برای سرور مقصد همین یک خط به عنوان درخواست کفایت می‌کند تا بداند چه چیزی را باید به ما تحویل دهد.

در خط دوم، سایت مورد نظر ذکر می‌شود. این خط توسط سرور وب استفاده می‌شود تا اگر چند سایت بر روی سرور قرار دارد، تشخیص دهد که کدامیک از آنها را باید نمایش دهد. لذا اگر تنها یک سایت بر روی سرور باشد، این خط کارایی ندارد. این خط جزو استاندارد HTTP است و باید همواره ذکر شود.

خط‌های بعدی نوع کاوشگر مبدا و سیستم عامل و زبان‌های قابل فهم و زمان و غیره را مشخص می‌کند تا سرور مقصد بر اساس آنها صفحه مناسب را ارائه دهد. این خط‌ها تنها برای کاوشگران حرفه‌ای وب مهم هستند.

سرور مقصد پس از دریافت این اطلاعات و پردازش آن، صفحه مورد نظر را پیدا کرده در قالب پاسخ HTTP با فرمت زیر ارسال می‌کند:

 HTTP/1.1 200 OK
 Date: Mon, 23 May 2005 22:38:34 GMT
 Server: Apache/1.3.3.7 (Unix) (Red-Hat/Linux)
 Last-Modified: Wed, 08 Jan 2003 23:11:55 GMT
 Etag: "3f80f-1b6-3e1cb03b"
 Accept-Ranges: bytes
 Content-Length: 438
 Connection: close
 Content-Type: text/html; charset=UTF-8

این پاسخ نمایانگر مشخصات سرور و وضعیت پاسخ است که توسط کاوشگر ما پردازش می‌شود. در ادامه این سرآیند، معمولا حجم انبوهی داده به قالب HTML (زبان ارائه وب) پیوست شده است که متن است، ولی توسط چشم انسان به سادگی قابل فهم نیست ولی توسط برنامه کاوشگر وب قابل درک است. کاوشگر وب این داده را پردازش می‌کند و در قالب صفحات وب بر روی صفحه رسم می‌کند تا کاربر آنها را مرور کند.

نکته‌ای قابل توجه آنست که در میانه پردازش این داده، کاوشگر گاهی مجددا به آدرسی دیگر (مثل آدرس یک تصویر یا یک تکه صوت یا اسکریپت) بر می‌خورد و مجددا به همان سرور درخواستی ارسال می‌کند تا آن تکه داده را نیز دریافت کند و در رسم صفحه به کار بگیرد.

چگونگی فیلترینگ

یک فیلترینگ خوب، باید در مراحل مختلف بر روی درخواست و پاسخ اعمال شود. ابتدا اینکه در مرحله DNS باید پاسخ مقتضی برگرداند، که البته به راحتی قابل رفع است. سپس در مرحله درخواست باید خط اول و دوم را بررسی کند و آدرس سایت مقصد را استخراج کند و بر اساس آن تشخیص دهد که فیلتر شده است یا خیر. اگر فیلتری شده بود، پاسخ HTTP از نوع انتقال صفحه ( ۳۰۱ Redirect)‌ به آدرس صفحه فیلترینگ را به جای آدرس اصلی برگرداند.

در مرحله سوم باید بر اساس محتوای داده بازگشتی از سایت مقصد، تصمیم بگیرد که آنرا نگه دارد یا با انتقال تغییر دهد. اینکار از نظر پردازش بسیار هزینه‌بر است زیرا باید یک برنامه پیچیده تمام داده را مطالعه و پردازش کند و الگو‌های مورد نظر را تطبیق دهد، ولی معمول‌ترین روشیست که استفاده می‌شود.

در ایران فیلترینگ تنها در فاز دوم (تشخیص آدرس از سرآیند) آنهم به صورت ناقص صورت می‌گیرد، یعنی تنها سرآیند Host بررسی می‌شود و آدرس آن با لیست فیلترینگ تطبیق یک به یک داده می‌شود، به همین دلیل بود که مثلا تا مدت بسیاری آدرس ww.facebook.com برای دسترسی به فیس بوک قابل استفاده بود.

راه ساده عبور از فیلترینگ

از آنجایی که تنها سرآیند Host در درخواست ما بررسی می‌شود و آدرس می‌تواند در خط اول درخواست جای گیرد و Host به کلی حذف شود (یا با آدرس سایتی بی مورد جایگزین شود)، راه بسیار ساده‌ای برای رفع فیلترینگ سایت‌هایی که سرور اختصاصی دارند وجود دارد. البته سایت‌هایی که با دیگر سایت‌ها در یک سرور مشترک هستند نیاز به Host دارند تا سرورشان تشخیص دهد کدام سایت درخواست شده است و مثلا همین سایت بنده را با اعمال این راه‌حل نمی‌توانید مرور کنید.

قبل از توضیح روش اعمال، فرآیند زیر را انجام دهید تا بیشتر با جزئیات کار آشنا شوید:

  1. ترمینال (Command Prompt) خود را اجرا نمایید و دستور زیر را وارد کنید
  2. telnet facebook.com 80
  3. دستور فوق یک اتصال به سرور موجود در facebook.com بر روی پورت ۸۰ ایجاد می‌کند (همان کاری که کاوشگر می‌کند). پس از برقرار اتصال پیامی مبنی بر آماده بودن ارسال اطلاعات به شما می‌دهد. حال باید درخواست HTTP را وارد کرد.
  4. GET /profile/abiusx HTTP/1.1
  5. Host: www.facebook.com
  6. پس از وارد کردن این دو خط، دوبار کلید Enter را فشار دهید. پس از چند لحظه پاسخ بر روی صفحه ظاهر خواهد شد :
HTTP/1.1 403 Forbidden

<html><head><meta http-equiv="Content-Type" content="text/html; charset=windows-1256"><title>LCT4-3
</title></head><body><iframe src="http://10.10.34.34?type=Invalid Site&policy=MainPolicy " style="width: 100%; height: 100%" scrolling="no" marginwidth="0" marginheight="0" frameborder="0" vspace="0" hspace="0"></iframe></body></html>

کد نتیجه ۴۰۳ یعنی عدم اجازه دسترسی، به همراه بدنه‌ای که کاوشگر شمارا به سایتی در آدرس http://10.10.34.34 هدایت می‌کند به عنوان پاسخ ارسال شده است (در زبان HTML) با کمی مرور متن پاسخ این اطلاعات مشخص است. اکنون فرآیند زیر را انجام دهید تا پاسخ فیلتر نشود :

  1. ترمینال خود را باز نمایید و دستور زیر را وارد کنید :
  2. telnet facebook.com 80
  3. پس از برقرار اتصال تک خط درخواست زیر را وارد کرده، دوبار کلید Enter را بزنید:
  4. GET http://www.facebook.com/profile/abiusx HTTP/1.1
  5. پاسخی به صورت زیر خواهد داد، که یعنی صفحه‌ای که شما می‌خواهید در آدرس دیگری قرار دارد (از آنجایی که نوع کاوشگر را مشخص نکرده‌اید، فیس بوک فکر می‌کند نوع خاصی از تلفن همراه هستید که صفحه آن آدرس خاصی دارد). آن آدرس را مجددا درخواست کنید و دوبار Enter بزنید:
  6. GET http://www.facebook.com/common/browser.php HTTP/1.1
  7. حجم نسبتا زیادی اطلاعات در قالب HTML خروجی داده می‌شود که همان صفحه فیس بوک است.
HTTP/1.1 302 Found
Location: http://www.facebook.com/common/browser.php
Content-Type: text/html; charset=utf-8
X-FB-Server: 10.27.60.111
Date: Sun, 31 Jul 2011 03:05:00 GMT
Content-Length: 0

انجام این فرآیند به صورت دستی بسیار دشوار است، و همچنین خروجی HTML برای انسان قابل فهم نیست. اما این مکانیزم را به سادگی می‌توانید در مرورگرهای قدرتمند پیاده کنید. به عنوان مثال در مرورگر Firefox افزونه Modify Headers را نصب کنید. پس از اتمام نصب و راه‌اندازی مجدد مرورگر، از منوی Tools صفحه تنظیمات آنرا باز کنید. در فیلد های موجود Action را معادل Filter و Header name را معادل Host قرار داده، کلید Add را فشار دهید. اکنون فیلتر اضافه شده در لیست را انتخاب کرده، کلید Enable را فشار دهید تا چراغ کنار آن سبز شود.

حال به آدرس www.abiusx.com مراجعه کنید. با پیام خطای سرور مواجه خواهید شد، زیرا نتوانسته تشخیص دهد کدام سایت روی آنرا خواسته‌اید. اما اگر به سایت www.facebook.com مراجعه نمایید مشاهده می‌کنید که مشکلی وجود ندارد و سایت بدون مشکل باز می‌شود. (البته توجه داشته باشید که برخی از تصاویر، به دلیل قرار داشتن بر روی سرورهای چندسایتی، بار نخواهند شد).

پس از اینکه از سایت‌های مورد نظر (که قبلا فیلتر بودند)‌ دیدن کردید، می‌توانید مجددا از پنجره تنظیمات Modify Headers، فیلتر را انتخاب کرده آنرا غیر فعال کنید.

 

VN:F [1.9.5_1105]
امتیاز: ۸٫۶/۱۰ (۳۰ رای)

WB-Tree

VN:F [1.9.5_1105]
امتیاز: (از ۴ رای)

آقای Jaffer یک پیاده‌سازی تر و تمیز و خوب و کاملا متن باز و قابل استفاده از B+ Tree انجام داده که خیلی راحت قابل استفاده هست و امکانات خوبی هم داره. ایشون از MIT هستند و زبان SCM که یک پیاده‌سازی آزاد و استاندارد از Scheme هست رو به همراه SLib پیاده‌سازی کرده.

این کتابخونه که WB-Tree نام داره، در سی پلاس پلاس قابل استفاده نبود که بعد از کمی تعاملات و همکاری بین من و ایشون، قابل استفاده شد و یک راهنما و یک برنامه نمونه برای اون نوشتم. آدرس راهنما به شرح زیر هست :

http://abiusx.com/code/wb/

این پروژه و راهنما جهت پروژه ذخیره و بازیابی دانشجویان مهندسی کامپیوتر شهید بهشتی مهیا شده ولی در انواع پروژه‌های دیگر با ضریب اطمینان بالایی قابل استفاده هست. این راهنما در حال حاضر به عنوان راهکار اصلی استفاده از کتابخانه درC++ هم در سایت اصلی مطرح شده. امیدوارم مفید باشه.

VN:F [1.9.5_1105]
امتیاز: ۸٫۵/۱۰ (۶ رای)