mirror of
https://github.com/carlospolop/hacktricks
synced 2025-02-17 06:28:27 +00:00
274 lines
18 KiB
Markdown
274 lines
18 KiB
Markdown
# Memcacheコマンド
|
||
|
||
<details>
|
||
|
||
<summary><a href="https://cloud.hacktricks.xyz/pentesting-cloud/pentesting-cloud-methodology"><strong>☁️ HackTricks Cloud ☁️</strong></a> -<a href="https://twitter.com/hacktricks_live"><strong>🐦 Twitter 🐦</strong></a> - <a href="https://www.twitch.tv/hacktricks_live/schedule"><strong>🎙️ Twitch 🎙️</strong></a> - <a href="https://www.youtube.com/@hacktricks_LIVE"><strong>🎥 Youtube 🎥</strong></a></summary>
|
||
|
||
* **サイバーセキュリティ会社**で働いていますか? **HackTricksで会社を宣伝**したいですか?または、**PEASSの最新バージョンにアクセスしたり、HackTricksをPDFでダウンロード**したいですか?[**SUBSCRIPTION PLANS**](https://github.com/sponsors/carlospolop)をチェックしてください!
|
||
* [**The PEASS Family**](https://opensea.io/collection/the-peass-family)を見つけてください。独占的な[**NFT**](https://opensea.io/collection/the-peass-family)のコレクションです。
|
||
* [**公式のPEASS&HackTricksのスワッグ**](https://peass.creator-spring.com)を手に入れましょう。
|
||
* [**💬**](https://emojipedia.org/speech-balloon/) [**Discordグループ**](https://discord.gg/hRep4RUj7f)または[**telegramグループ**](https://t.me/peass)に**参加**するか、**Twitter**で**フォロー**してください[**🐦**](https://github.com/carlospolop/hacktricks/tree/7af18b62b3bdc423e11444677a6a73d4043511e9/\[https:/emojipedia.org/bird/README.md)[**@carlospolopm**](https://twitter.com/hacktricks_live)**。**
|
||
* **ハッキングのトリックを共有するには、PRを** [**hacktricks repo**](https://github.com/carlospolop/hacktricks) **と** [**hacktricks-cloud repo**](https://github.com/carlospolop/hacktricks-cloud) **に提出してください。**
|
||
|
||
</details>
|
||
|
||
## コマンドのチートシート
|
||
|
||
**From** [**https://lzone.de/cheat-sheet/memcached**](https://lzone.de/cheat-sheet/memcached)\*\*\*\*
|
||
|
||
サポートされているコマンド(公式のものと非公式のもの)は、[doc/protocol.txt](https://github.com/memcached/memcached/blob/master/doc/protocol.txt)ドキュメントに記載されています。
|
||
|
||
残念ながら、構文の説明は実際には明確ではなく、既存のコマンドをリストアップする単純なヘルプコマンドの方がはるかに良いでしょう。以下は、[source](https://github.com/memcached/memcached)(2016年8月19日現在)で見つけることができるコマンドの概要です:
|
||
|
||
| コマンド | 説明 | 例 |
|
||
| --------------------- | --------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
||
| get | 値を読み取る | `get mykey` |
|
||
| set | キーを無条件で設定する | <p><code>set mykey <flags> <ttl> <size></code><br><br><p>Unix CLIツールを使用する場合は、改行として\r\nを使用してください。例えば</p> <code>printf "set mykey 0 60 4\r\ndata\r\n" | nc localhost 11211</code></p> |
|
||
| add | 新しいキーを追加する | `add newkey 0 60 5` |
|
||
| replace | 既存のキーを上書きする | `replace key 0 60 5` |
|
||
| append | 既存のキーにデータを追加する | `append key 0 60 15` |
|
||
| prepend | 既存のキーにデータを先頭に追加する | `prepend key 0 60 15` |
|
||
| incr | 数値キーの値を指定された数値だけ増やす | `incr mykey 2` |
|
||
| decr | 数値キーの値を指定された数値だけ減らす | `decr mykey 5` |
|
||
| delete | 既存のキーを削除する | `delete mykey` |
|
||
| flush\_all | すべてのアイテムを即座に無効にする | `flush_all` |
|
||
| flush\_all | n秒後にすべてのアイテムを無効にする | `flush_all 900` |
|
||
| stats | 一般的な統計情報を表示する | `stats` |
|
||
| | メモリの統計情報を表示する | `stats slabs` |
|
||
| | より高いレベルの割り当て統計情報を表示する | `stats malloc` |
|
||
| | アイテムに関する情報を表示する | `stats items` |
|
||
| | | `stats detail` |
|
||
| | | `stats sizes` |
|
||
| | 統計カウンターをリセットする | `stats reset` |
|
||
| lru\_crawler metadump | キャッシュ内のアイテムの(ほとんどの)メタデータをダンプする | `lru_crawler metadump all` |
|
||
| version | サーバーのバージョンを表示する。 | `version` |
|
||
| verbosity | ログレベルを上げる | `verbosity` |
|
||
| quit | セッションを終了する | `quit` |
|
||
|
||
#### トラフィック統計 <a href="#traffic-statistics" id="traffic-statistics"></a>
|
||
|
||
現在のトラフィック統計を問い合わせることができます。
|
||
```
|
||
stats
|
||
```
|
||
以下は、接続数、送受信バイト数などを表示するリストです。
|
||
|
||
出力例:
|
||
```
|
||
STAT pid 14868
|
||
STAT uptime 175931
|
||
STAT time 1220540125
|
||
STAT version 1.2.2
|
||
STAT pointer_size 32
|
||
STAT rusage_user 620.299700
|
||
STAT rusage_system 1545.703017
|
||
STAT curr_items 228
|
||
STAT total_items 779
|
||
STAT bytes 15525
|
||
STAT curr_connections 92
|
||
STAT total_connections 1740
|
||
STAT connection_structures 165
|
||
STAT cmd_get 7411
|
||
STAT cmd_set 28445156
|
||
STAT get_hits 5183
|
||
STAT get_misses 2228
|
||
STAT evictions 0
|
||
STAT bytes_read 2112768087
|
||
STAT bytes_written 1000038245
|
||
STAT limit_maxbytes 52428800
|
||
STAT threads 1
|
||
END
|
||
```
|
||
#### メモリ統計 <a href="#memory-statistics" id="memory-statistics"></a>
|
||
|
||
現在のメモリ統計をクエリで取得することができます。
|
||
```
|
||
stats slabs
|
||
```
|
||
# memcache-commands
|
||
|
||
## Introduction
|
||
|
||
Memcache is a widely used distributed memory caching system. It is commonly used to speed up dynamic database-driven websites by caching data and objects in memory to reduce the number of times an external data source (such as a database or API) needs to be accessed.
|
||
|
||
## Basic Commands
|
||
|
||
### SET
|
||
|
||
The `SET` command is used to store a value in the cache. It takes three arguments: the key, the value, and an optional expiration time in seconds.
|
||
|
||
```bash
|
||
SET key value [expiration]
|
||
```
|
||
|
||
### GET
|
||
|
||
The `GET` command is used to retrieve a value from the cache. It takes one argument: the key.
|
||
|
||
```bash
|
||
GET key
|
||
```
|
||
|
||
### DELETE
|
||
|
||
The `DELETE` command is used to remove a value from the cache. It takes one argument: the key.
|
||
|
||
```bash
|
||
DELETE key
|
||
```
|
||
|
||
### FLUSH_ALL
|
||
|
||
The `FLUSH_ALL` command is used to remove all values from the cache.
|
||
|
||
```bash
|
||
FLUSH_ALL
|
||
```
|
||
|
||
## Advanced Commands
|
||
|
||
### INCR
|
||
|
||
The `INCR` command is used to increment the value of a key by a specified amount. If the key does not exist, it is created with an initial value of 0.
|
||
|
||
```bash
|
||
INCR key amount
|
||
```
|
||
|
||
### DECR
|
||
|
||
The `DECR` command is used to decrement the value of a key by a specified amount. If the key does not exist, it is created with an initial value of 0.
|
||
|
||
```bash
|
||
DECR key amount
|
||
```
|
||
|
||
### APPEND
|
||
|
||
The `APPEND` command is used to append a value to the existing value of a key.
|
||
|
||
```bash
|
||
APPEND key value
|
||
```
|
||
|
||
### PREPEND
|
||
|
||
The `PREPEND` command is used to prepend a value to the existing value of a key.
|
||
|
||
```bash
|
||
PREPEND key value
|
||
```
|
||
|
||
### CAS
|
||
|
||
The `CAS` command is used to perform a "check and set" operation. It allows you to update a value only if it has not been modified by another client since you last retrieved it.
|
||
|
||
```bash
|
||
CAS key value cas_unique_id [expiration]
|
||
```
|
||
|
||
### STATS
|
||
|
||
The `STATS` command is used to retrieve statistics about the memcache server.
|
||
|
||
```bash
|
||
STATS
|
||
```
|
||
|
||
### VERSION
|
||
|
||
The `VERSION` command is used to retrieve the version of the memcache server.
|
||
|
||
```bash
|
||
VERSION
|
||
```
|
||
|
||
### FLUSH_ALL
|
||
|
||
The `FLUSH_ALL` command is used to remove all values from the cache.
|
||
|
||
```bash
|
||
FLUSH_ALL
|
||
```
|
||
|
||
### QUIT
|
||
|
||
The `QUIT` command is used to close the connection to the memcache server.
|
||
|
||
```bash
|
||
QUIT
|
||
```
|
||
|
||
## Conclusion
|
||
|
||
These are some of the most commonly used commands in memcache. Understanding how to use these commands effectively can greatly enhance your ability to work with memcache and optimize the performance of your applications.
|
||
```
|
||
STAT 1:chunk_size 80
|
||
STAT 1:chunks_per_page 13107
|
||
STAT 1:total_pages 1
|
||
STAT 1:total_chunks 13107
|
||
STAT 1:used_chunks 13106
|
||
STAT 1:free_chunks 1
|
||
STAT 1:free_chunks_end 12886
|
||
STAT 2:chunk_size 100
|
||
STAT 2:chunks_per_page 10485
|
||
STAT 2:total_pages 1
|
||
STAT 2:total_chunks 10485
|
||
STAT 2:used_chunks 10484
|
||
STAT 2:free_chunks 1
|
||
STAT 2:free_chunks_end 10477
|
||
[...]
|
||
STAT active_slabs 3
|
||
STAT total_malloced 3145436
|
||
END
|
||
```
|
||
もし、メモリキャッシュのインスタンスに十分なメモリがあるかどうか確信が持てない場合は、"stats"コマンドで表示される"evictions"カウンターに注意してください。インスタンスに十分なメモリがある場合、"evictions"カウンターは0または増加していないはずです。
|
||
|
||
#### 使用されているキーはどれですか? <a href="#which-keys-are-used" id="which-keys-are-used"></a>
|
||
|
||
現在のキーのセットを直接確認するための組み込み関数はありません。ただし、以下のコマンドを使用して、使用されているキーを推測することができます。
|
||
```
|
||
stats items
|
||
```
|
||
## Command to Determine How Many Keys Exist
|
||
|
||
To determine the number of keys that exist in a Memcache server, you can use the `stats` command. This command provides statistics about the server, including the total number of keys stored.
|
||
|
||
To execute the command, follow these steps:
|
||
|
||
1. Connect to the Memcache server using a Memcache client.
|
||
2. Send the `stats` command to the server.
|
||
3. Parse the response to extract the value of the `total_items` statistic.
|
||
|
||
Here is an example of how to execute the command using Telnet:
|
||
|
||
```bash
|
||
$ telnet <memcache_server_ip> 11211
|
||
stats
|
||
```
|
||
|
||
The server will respond with a list of statistics. Look for the `total_items` statistic and note its value. This value represents the total number of keys stored in the Memcache server.
|
||
|
||
Keep in mind that the `stats` command provides various other statistics as well, which can be useful for monitoring and troubleshooting purposes.
|
||
```
|
||
stats items
|
||
STAT items:1:number 220
|
||
STAT items:1:age 83095
|
||
STAT items:2:number 7
|
||
STAT items:2:age 1405
|
||
[...]
|
||
END
|
||
```
|
||
これにより、使用されているキーを確認することができます。既にmemcacheアクセスを行っているPHPスクリプトからキー名をダンプするには、[100days.de](http://100days.de/serendipity/archives/55-Dumping-MemcacheD-Content-Keys-with-PHP.html)のPHPコードを使用できます。
|
||
|
||
<details>
|
||
|
||
<summary><a href="https://cloud.hacktricks.xyz/pentesting-cloud/pentesting-cloud-methodology"><strong>☁️ HackTricks Cloud ☁️</strong></a> -<a href="https://twitter.com/hacktricks_live"><strong>🐦 Twitter 🐦</strong></a> - <a href="https://www.twitch.tv/hacktricks_live/schedule"><strong>🎙️ Twitch 🎙️</strong></a> - <a href="https://www.youtube.com/@hacktricks_LIVE"><strong>🎥 Youtube 🎥</strong></a></summary>
|
||
|
||
* **サイバーセキュリティ企業**で働いていますか? **HackTricksで会社を宣伝**したいですか?または、**PEASSの最新バージョンやHackTricksのPDFをダウンロード**したいですか?[**SUBSCRIPTION PLANS**](https://github.com/sponsors/carlospolop)をチェックしてください!
|
||
* [**The PEASS Family**](https://opensea.io/collection/the-peass-family)を発見しましょう。独占的な[**NFT**](https://opensea.io/collection/the-peass-family)のコレクションです。
|
||
* [**公式のPEASS&HackTricksグッズ**](https://peass.creator-spring.com)を手に入れましょう。
|
||
* [**💬**](https://emojipedia.org/speech-balloon/) [**Discordグループ**](https://discord.gg/hRep4RUj7f)または[**telegramグループ**](https://t.me/peass)に参加するか、**Twitter**で[**🐦**](https://github.com/carlospolop/hacktricks/tree/7af18b62b3bdc423e11444677a6a73d4043511e9/\[https:/emojipedia.org/bird/README.md)[**@carlospolopm**](https://twitter.com/hacktricks_live)**をフォロー**してください。
|
||
* **ハッキングのトリックを共有するには、PRを** [**hacktricks repo**](https://github.com/carlospolop/hacktricks) **と** [**hacktricks-cloud repo**](https://github.com/carlospolop/hacktricks-cloud) **に提出してください。**
|
||
|
||
</details>
|