You are ignoring consumers giving their money to companies for goods and services.
The most obvious case are companies that pay dividends but earnings growth and resulting stock price growth also represent the same thing.
Compare a CD / Bond to a stock.
The CD pays 1% per year. If you put $10,000 into it, you will get $100 per year in interest.
Say you have a company that pays $200 per year on $10,000 of stock. Is $10,000 a fair price? Or are people likely to bid it up until it is paying about 1% per year? There is some risk, but it's likely the stock will go up until it pays a rate closer to the CD. So the stock might go to $18,000 and pay you $200 per year.
Now say the company is increasing earnings by 10% per year. So it will pay $220 next year, $242 the year after that and so on. So reasonable people will now pay even more for the stock. It might go up to $19,000 this year (and more in the future).
Finally, say bad news -- the companies earnings are not going up to $242 as planned but instead are dropping to $180 because of a new invention, new law, or new competitor. And it's earnings are likely to be $160 the year after that. So now, a reasonable person might only want to pay $14,000 for the stock.
---
Just to make things interesting make a lot of this a matter of opinion and not facts. A new law *may* be passed... a new competitor *may* start up. And different people have different opinions on how likely that is to occur.
---
And then add oscillation around the "ideal" value. Every time the stock price moves- it slightly overshoots. it takes it time to stabilize on a ideal value and by the time it is going to- some fresh news changes the ideal value. And of course-- occasionally a majority of people will be afraid and unwilling to buy the stock at it's ideal value and other times a majority of people will be irrationally exhuberant and willing to buy the stock above it's ideal value.
---
Anyway.. long story short- it's not a pure ripoff. For the most part, you don't "get rich" but you do preserve purchasing power adjusted for inflation. Mainly, you need to save hard. People who try to get rich are gambling- some will win big- many will lose big.