Penetration Testing trên Memcached Server / Beta

Trong bài trước chúng ta đã xây dựng Memcached Server trên nền Ubuntu 18.04, hãy xem bài học bên dưới còn nếu ai không dựng được hãy tải về từ Thư Viện Tin Học để tiến hành exploit Memcached Server.

Nội Dung Bài Học

  • Dump data từ Memcached server một cách thủ công.
  • Dump data với libmemcached-tools.
  • Dump data với Metasploit.
  • Giám sát với Watchers.

Yêu Cầu

Mục tiêu : Memcached Server chạy trên hệ thống Ubuntu 18.04

Attacker: Kali Linux 2019.1

Bắt Đầu Tấn Công & Khai Thác !!

Dump data từ Memcached server một cách thủ công

Sau khi khởi động pentest lab gồm Kali Linux và Memcacheed server hãy tiến hành quét với nmap. Trong tình huống này mục tiêu có địa chỉ IP là 192.168.1.32

#nmap -sV -p- 192.168.1.32

Qua hình minh họa ta thấy Memcached đang chạy tại port 11211 / open.

Thử dùng nse để dò quét thêm trong tình huống này, nên kiểm tra xem có sẳn script này hay chưa, nếu không ha4yta3i về từ nmap.org.

#nmap -p11211 –script=memcached-info 192.168.1.32

Kết quả cho thấy kịch bản nmap đã thu được một số thông tin về Memcached server như là ID, Uptime, Architecture, MAC Address …

Thử kết nối đến Memcached server với telnet như lệnh sau.

#telnet 192.168.1.32 11211

As you can see in the above image, we are able to connect the Memcached Server through telnet. In such cases, the server is unprotected, hence, an attacker can gain access to the server without any obstacle because the server is not configured with SASL or any kind of firewall. Let’s go ahead and begin exploitation of the Memcached Server of which we gained access previously.

Như bạn có thể thấy trong hình trên, chúng tôi có thể kết nối Máy chủ Memcached thông qua telnet. Trong những trường hợp như vậy, máy chủ không được bảo vệ, do đó, kẻ tấn công có thể truy cập vào máy chủ mà không gặp bất kỳ trở ngại nào vì máy chủ không được cấu hình với SASL hoặc bất kỳ loại tường lửa nào. Hãy cùng nhau tiến lên và bắt đầu khai thác Máy chủ Memcached mà chúng tôi đã truy cập trước đó.

Type in a command version to do a version scan of the Memcached Server.

Nhập phiên bản lệnh để thực hiện quét phiên bản Máy chủ Memcached.

1version

The above data represents that the version of Memcached is 1.5.6 and it is running in a Ubuntu machine.

Dữ liệu trên cho thấy phiên bản Memcached là 1.5.6 và nó đang chạy trong máy Ubuntu.

Now, let’s get straight to fetch the valuable data stored in the server. Type the command shown below to print all the general statistics of the server.

Bây giờ, hãy để trực tiếp lấy dữ liệu có giá trị được lưu trữ trong máy chủ. Nhập lệnh hiển thị bên dưới để in tất cả các số liệu thống kê chung của máy chủ.

1stats

The above information shows the current traffic statistics. It serves the number of connections, data is stored into the cache, cache hit ratios and detailed information on the memory usage and distribution of information through the slab allocation used to store individual items.

Các thông tin trên cho thấy số liệu thống kê giao thông hiện tại. Nó phục vụ số lượng kết nối, dữ liệu được lưu trữ vào bộ đệm, tỷ lệ nhấn bộ đệm và thông tin chi tiết về việc sử dụng bộ nhớ và phân phối thông tin thông qua phân bổ bản mỏng được sử dụng để lưu trữ các mục riêng lẻ.

Now, we will run another command to fetch the slab statistics. Slabs are created and allocated for storing information within the cache. Run the command shown below.

Bây giờ, chúng tôi sẽ chạy một lệnh khác để lấy số liệu thống kê bản. Các tấm được tạo và phân bổ để lưu trữ thông tin trong bộ đệm. Chạy lệnh hiển thị dưới đây.

1stats slabs

As you can observe in the above image, currently there is only one slab present in the server whose slab number is 1.

Như bạn có thể quan sát trong hình trên, hiện tại chỉ có một phiến trong máy chủ có số phiến là 1.

Now, let’s run a command mentioned below to fetch count, age, eviction, expired etc. organized by slab ID.

Bây giờ, hãy để Lôi chạy một lệnh được đề cập dưới đây để tìm nạp số lượng, tuổi, trục xuất, hết hạn, v.v. được tổ chức bởi ID phiến.

1stats items

The above image gives us an insight into how the data is organized in slab ID 1.

Hình ảnh trên cho chúng ta cái nhìn sâu sắc về cách tổ chức dữ liệu trong bản ID 1.

Now, let’s run the command below to dump all the keys present in a particular slab.

Bây giờ, hãy để Lôi chạy lệnh bên dưới để kết xuất tất cả các khóa có trong một phiến cụ thể.

1stats cachedump 1 0

Here 1 and 0 are the parameters,

1 = slab ID.

0 = It represents the number of keys you want to dump, 0 will dump all the keys present in the slab ID respectively.

0 = Nó đại diện cho số lượng khóa bạn muốn đổ, 0 sẽ đổ tất cả các khóa có trong ID bản tương ứng.

The above image represents ITEM <item_key> [<item_size> b; <expiration_timestamp> s]

Now, we can simply use the get command to fetch the values stored in the keys as shown below.

123get first get secondget third

As you can see in the above image, we have successfully dumped the data stored in the key values.

Dumping data using libmemcached-tools

Dumping of data using this toolkit makes the work a lot easier. So, let’s start by installing libmemcached-tools in our system by typing in the following command.

Việc đổ dữ liệu bằng bộ công cụ này giúp công việc dễ dàng hơn rất nhiều. Vì vậy, hãy bắt đầu bằng cách cài đặt libmemcached-tools trong hệ thống của chúng tôi bằng cách gõ lệnh sau.

1apt install libmemcached-tools

Now that we have installed libmemcached-tools let’s start using it by typing in the following command.

1memcstat –servers=192.168.1.33

The above command will give pretty much the same result as the stats command which we had used earlier while fetching the server statistics manually.

Now, let’s get straight to dumping the key values stored in the server. Run the command given below.

1memcdump –servers=192.168.1.33

As you can see in the above image, we have dumped all the keys present in the server currently.

Now, let’s dump all the values stored in the keys respectively. Run the command shown below.

1memccat –servers=192.168.1.33 fifth fourth third second first

The above command fetched us all the data stored in the respective key values. An attacker can use libmemcached-tools to easily upload any malicious file to the server too. Here, we will be showing an example of how to upload a file in the server.

Type the command shown below.

1memccp –servers=192.168.1.33 file

Here, the memccp command is uploading a file named “file.txt” present in the root directory of our system. Now, let’s use memcat to view the content of the file which we have uploaded in the server.

1memcat –servers=192.168.1.33 file

As you can see, the above command fetched us the content of the file.

Dumping Data using Metasploit

As we all know, no exploitation is complete without using the Metasploit Framework once. So let’s dig in and see how we can exploit Memcached using Metasploit.

Fire up the Metasploit Framework and search Memcache.

1search memcache

The above image shows that there are currently 4 auxiliaries present in Metasploit.

We will be using auxiliary/gather/memcached_extractor to fetch the keys and the values stored in it. Run the command given below.

1use auxiliary/gather/memcached_extractor

Once you have successfully imported the auxiliary in the Metasploit Framework, just set the rhost and then run the auxiliary. We know that Memcached stores data temporarily. So the above image shows that the auxiliary had fetched us both the Key and the Value currently present in the Memcached Server and stored it in its default location /root/.msf4/loot/20190218044841_default_192.168.1.35_memcached.dump_286171.txt

Monitoring using Watchers

Watchers are a way to connect to Memcached and monitor all the actions being performed internally.

Now connect the Memcached using telnet and type the command shown below.

1watch fetchers

The command line OK indicates that watcher is ready to send logs.

As you can see in the above image, all the actions which are being performed in the server are shown here live.

Conclusion

In this article, we have learned beginner level methods to exploit Memcached. In our future articles, we will be showing advanced methods to exploit Memcached Servers.

Stay tuned!!

Comments